Twitter API -- update statuses endpoint



Hey guys, I’m trying to use the twitter api to post a status with an attached image. How can I make use of the media_ids property? I don’t understand how I can derive a media_id from an actual image element.


You’ll have to upload it through the media endpoint(s) which will then return an id for you to use in the status.


Would you mind providing a simple example?


It seems to me that uploading the media through the media endpoint would post the photo. I don’t want to have to post twice for one share.


I use this framework:

Basically it goes:

    $request = new \Abraham\TwitterOAuth\TwitterOAuth(


                $media = $request->upload('media/upload', [
                    'media' => $attachment['path']

                $mediaIds[] = $media['media_id_str'];

               $result = $request->post(
                    'status' => 'Your message',
                    'media_ids' => implode(',', $mediaIds)

It won’t post the image twice, it just allows you to upload multiple images as up to 4 images can be used per tweet. You can also attach that media id to more than one tweet.


I don’t use PHP, is there a way I can do this using JavaScript?
Also, just for clarity, $request.result.media_id’s would hold the media_ids value that would be used in the tweet?


Yes it can be done with Javascript but I don’t have any code snippets available for that.

The result from the $request->upload call contains media_id and media_id_str which can be used in the tweet, correct.


I was trying to accomplish this task by just reading excerpts from the documentation.
I’ll stop being lazy and do my research thoroughly. Thanks for the help!


I realise you’re using Javascript, but we do have a sample app in Python that is quite readable and leads you through the whole process of uploading media and creating Tweets with media attached. You may find that a useful reference.


It’s always good to read.