0

I came across a strange issue where some images won't show in the API console even though a user has posted one with a tweet.

Notice the second tweet in this timeline (right now anyway) it starts with ... World premiere of new #play 'Between a Man and a Woman ... https://twitter.com/BatterseaBarge

In some cases an image gets posted and gets a :large appended to the image url. ie.

<img src="https://pbs.twimg.com/media/exmaple.jpg:large"/>

Now when images like this are in a post and I run a test on the API console no media_url is coming up in the response. Of course when :large is not appended to a url it will come up in the response. here is name to test... BatterseaBarge https://dev.twitter.com/rest/tools/console

It seems like a bug in the API in my opinion. Anyone have any ideas?

Follow-up to answer: As noted below that is the answer for me. I use an array to get the user_timeline so for others who do it similar to this, hope it helps. Just an additional note this does show a lot more stuff so the load time will probably slow down a bit too for those who are creating their own twitter feeds. Caching is always best for sure!

$fetchedTweets = $connection->get(
                'statuses/user_timeline',
                array(
                    'tweet_mode' => 'extended',
                    'screen_name' => $name,
                    'count' => $totalToFetch,
                    'exclude_replies' => $excludeReplies,
                    'images' => $description_image,
                    'include_rts' => $show_retweets,
                )
            );
SlickRemix
  • 456
  • 6
  • 17
  • I don't understand the question. The tweet - https://twitter.com/BatterseaBarge/status/779978221479690240 - has an image - https://pbs.twimg.com/media/CtMJO81XgAAxDkn.jpg:large - where are you seeing the error? What API call are you trying? – Terence Eden Sep 26 '16 at 09:55
  • Some images won't show in the API console even though a user has posted one with a tweet, why is this? No error is happening, this media url just does not show in the API tool. I am using the tool provided by twitter. https://dev.twitter.com/rest/tools/console – SlickRemix Sep 26 '16 at 14:49

1 Answers1

4

Ah! You've run across the new style of Tweets. As per Twitter's documentation new tweets don't count media URLs in the body.

In order to prevent new tweets breaking old clients, you need to include some options in your code.

At the moment, you're calling https://api.twitter.com/1.1/statuses/show/779978221479690240.json and getting back something like:

"text": "World premiere of new #play 'Between a Man and a Woman' TONIGHT, MON & TUES @BatterseaBarge! Tkts… https://t .co/vZnDYowteX",

The new style of Tweets requires you to add the option tweet_mode=extended

For example, calling https://api.twitter.com/1.1/statuses/show/779978221479690240.json?tweet_mode=extended

Will get you back:

"full_text": "World premiere of new #play 'Between a Man and a Woman' TONIGHT, MON & TUES @BatterseaBarge! Tkts https://t .co/5yvfy4jwWX #moving #drama https://t .co/gs0gmC19PM", "media": [ { "id": 779977312918011900, "id_str": "779977312918011904", "indices": [ 141, 164 ], "media_url": "http://pbs.twimg.com/media/CtMJO81XgAAxDkn.jpg", "media_url_https": "https://pbs.twimg.com/media/CtMJO81XgAAxDkn.jpg",

So, add tweet_mode=extended and use the "full_text" attribute rather than just text.

Terence Eden
  • 14,034
  • 3
  • 48
  • 89