Twitter API strips retweets out of user timelines

Just discovered an interesting gotcha in the Twitter API: calls to the user_timeline method will have retweets stripped out.

From http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses-user_timeline:

Note: For backwards compatibility reasons, retweets are stripped out of the user_timeline when calling in XML or JSON (they appear with ‘RT’ in RSS and Atom). If you’d like them included, you can merge them in from statuses retweeted_by_me.

Huh. So in other words, making a call like this:

http://twitter.com/statuses/user_timeline.xml?screen_name=mmacaulay&count=1

might give you an empty result. Sneaky. Even if you increase the count parameter there or remove it altogether, you might end up with an empty result if the user does nothing but retweet things. If you want to see the same thing as you’d see by viewing the user’s timeline on twitter.com you’ll have to make an extra call to retweeted_by_me.

Dear Twitter developers: it would be nice if instead of stripping out the retweets you did one of two things:

  • If I make a request with count=n, return the first n non-retweet statuses
  • Allow me to specify whether or not retweets are included in the response via another parameter

Oh well. It’s Friday.

Posted February 5th, 2010 in Twitter.

3 comments:

  1. Cody:

    Did you end up creating a workaround?

  2. mmacaulay:

    Well, the “proper” workaround would be to do as is suggested by Twitter and merge retweets from retweeted_by_me, but the easier route would be to set the count parameter to some higher number where you think it will be likely that you’ll get at least one result back.

    Depending on the circumstances, you likely have to implement some kind of caching to avoid Twitter’s rate limiting, so merging retweeted_by_me or even making multiple calls with an increasing count parameter isn’t all that bad of a solution.

  3. Joel Adria:

    I ran into this too. It seems that retweeted_by_me needs authentication though, while user_timeline does not. Retweets are thus not available anonymously?

Leave a response:

  • Recent Posts

  • Archives