Lots of 404 errors when querying using twttr.widgets.createTweet


#1

Hey there.

I’m using Ember.js to display a list of a few tweets based on the tweetID. I render each tweet using the twttr.widgets.createTweet function, passing it the tweetID.

This only works for about 10% of tweets. The others simply don’t render. I looked at the browser network logs and I am seeing a LOT of 404s. The function appears to be requesting at https://syndication.twitter.com/tweets.json?ids=X for each tweetID. But most of these requests are returning 404s.

I am POSITIVE that the tweetIDs are correct. Here are some examples of tweetIDs I am using that return 404 and do not render:

520656411278458900
518441900312109060
521647625834344450

Here for comparison is one that worked:

518504436067737600

FYI even the provided ‘example’ tweet in the documentation (found here: https://dev.twitter.com/web/javascript/creating-widgets) doesn’t work. This has tweetID: 28 and it returns a 404 as well.

So clearly there is something not right on twitter’s side here, if nothing else the documentation is wrong.

Look forward to hearing some input on this issue :smile:

Best,
Sam


#2

The Tweet IDs you cited return 404s in our standard individual Tweet API, indicating the Tweet may not still exist. The failure to render the Tweet would be consistent across REST API, oEmbed, or JS factory functions.
https://dev.twitter.com/rest/reference/get/statuses/show/%3Aid

Tweet 28 used in the example has since been deleted; you can see the behavior at work by following the full Tweet URLs. Trying to access the Tweet permalink page on Twitter.com results in a 404. Any other reference to the Tweet ID returns a 404 as well.
https://twitter.com/ev/status/28

Tweets may fall out of existence if the author chooses to delete the Tweet, Twitter flags it for spam, etc. Your code should not expect a 100% hit rate for cited Tweets. If you want to be sure you always have some content, even if it’s not a fully rendered Embedded Tweet, check out the oEmbed API for fallback content to cache on your server.
https://dev.twitter.com/rest/reference/get/statuses/oembed


#3

OK, thanks for clearing that up niall.

So it seems that the tweets I am querying for really don’t exist any more. I will write some custom CSS and HTML to display in the case that twttr.widgets.createTweet doesn’t draw the tweet.

Does it have the ability for me to pass it a function to execute on a 404 error? I.e. if it doesn’t successfully query twitter, I want it to execute my fallback code instead.

-S


#4

Hi Sam,

We don’t have explicit error handling in that regard right now—in the future it might make sense for us to reject the createTweet() promise in the event of a 404, but for now the Promise will succeed, but will complete, but pass you an undefined argument (if successful, you’d get an element reference for the newly rendered Tweet.) You can test for this undefined argument to determine success or failure.

twttr.widgets.createTweet("28", document.body).then(function (result) {
  if (result === undefined) {
    // error 
  }
  else {
   // success
  }
});

#5