Ruby SDK upload() returns Media Ids I can't use


Recently started uploading images using twitter’s official ruby gem for the REST Api.

I’ve tried about a dozen times to upload a dozen different images using this SDK.

The first time I got an media ID and I used it in my update() options under the media_ids: option hash key.

And it worked!

But literally every single time since I get “Media ID Not Found” when trying to call update() using the very media id I got from the REST gem.

Anyone know what’s going on?


Do you mean the Ruby gem from sferik? Can you provide examples?


I am using the sferik gem like you guessed. Sorry for not including that in my OP.

Here’s an example:

twitter_client = do |config|
config.consumer_key = ENV[‘TWITTER_CONSUMER_KEY’]
config.consumer_secret = ENV[‘TWITTER_CONSUMER_SECRET’]
config.access_token = oauth_token
config.access_token_secret = oauth_token_secret
media_id = twitter_client.upload(tempfile)

The media is returned from this is the one I used where it worked the first time but not subsequent times.
Posting updates using media ids I’ve grabbed out of the JSON payload from GNIP works every time with our messaging sending code.


Are you trying to re-use the same mediaId for more than one Tweet, or am I misunderstanding what you’re describing here?

  1. I would like to upload a photo then immediately use it for the first time in media_options for the update() command.

  2. I would also like to tweet, under the tokens of the same user as 1), tweet a second time + possibly many more using the same media ID.

Currently I’m not able to tweet using it the media id even once because it says the media id could not be found. This is a different error than the one I get where it has expired after 24 hours and when it was uploaded by a different user using the REST api.

I meant when I said it worked the “first time” it worked the very first time I uploaded an image using the REST API – as in I was able to tweet using that media id. Every other image I have never been able to use at all.

Sorry for any confusion.



A mediaId (with a Tweet, not in “shared mode” with a DM) is one-time use. Once it is attached to a Tweet, it is “hardened” to the URL associated with the Tweet, and would need to be uploaded again.

We can clarify the specifics of this in our documentation, and we should do that. Unfortunately this is the way that the system works.


Ah. Yeah that information would be pretty critical if it was there.

Thanks for the clarification!


Sorry for the confusion. I’ll make a note to ensure that we make this more clear. It may take a month or so to update (we are working on some new developer resources) but I’m aware that this is not the first time this has been asked, and I can only apologise that existing resources are insufficiently explicit on this.


Does this apply to media ids gotten from gnip?


I am not aware that a media ID (sans URL to image) is available from any of the Gnip API endpoints. Can you clarify this for me?


Ah. Sorry 'bout that.

By Gnip I mean the native JSON objects that it returns, under the “media” property.