goddamnyouryan goddamnyouryan - 1 year ago 71
Ruby Question

Twitter API Hashtag Search Results don't contain images

I am not seeing image entities in my twitter API search results when I search for a hashtag, but if I use the api endpoint for that specific tweet I do.

Using this tweet for an example: https://twitter.com/mrbuddylee/status/733407581788463104

results = @twitter_client.search('#BecauseSummer', { include_entities: true, count: 200 })
result = results.first # not actually the first result, but just to illustrate.
=> {:hashtags=>[{:text=>"BecauseSummer", :indices=>[7, 21]}],
:symbols=>[], :user_mentions=>[],
:urls=>[{:url=>"TWITTER_SHORTENED_URL", :expanded_url=>"http://twitter.com/mrbuddylee/status/733407581788463104/photo/1", :display_url=>"pic.twitter.com/FAAY00SYQH", :indices=>[22, 45]}]}

but If I search for the tweet directly:

=> {:hashtags=>[{:text=>"BecauseSummer", :indices=>[7, 21]}],
:symbols=>[], :user_mentions=>[], :urls=>[],
:media=>[{:id=>733407573345341441, :id_str=>"733407573345341441", :indices=>[22, 45], :media_url=>"http://pbs.twimg.com/tweet_video_thumb/Ci2WTVzUkAE_gGD.jpg", :media_url_https=>"https://pbs.twimg.com/tweet_video_thumb/Ci2WTVzUkAE_gGD.jpg", :url=>"TWITTER_SHORTENED_URL", :display_url=>"pic.twitter.com/FAAY00SYQH", :expanded_url=>"http://twitter.com/mrbuddylee/status/733407581788463104/photo/1", :type=>"photo", :sizes=>{:small=>{:w=>340, :h=>173, :resize=>"fit"}, :thumb=>{:w=>150, :h=>150, :resize=>"crop"}, :medium=>{:w=>392, :h=>200, :resize=>"fit"}, :large=>{:w=>392, :h=>200, :resize=>"fit"}}}]}

Notice the media hash on the second result.

Why is this? Is it possible to get the media url on the initial search request?

Answer Source

I ended up doing a double query to make sure the images are returned:

results = @twitter_client.search('#BecauseSummer', { include_entities: true, count: 100 })
ids = .first(100).map(&:id)
results = @client.statuses(ids) 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download