Incorrect count from the Twitter API user_timeline | Rickard Andersson

Incorrect count from the Twitter API user_timeline

I encountered an issue with the Twitter API the other day that I’m sure other people have run into as well. I found little or no information on the issue online though, so here goes.

If you’re using the Twitter API to fetch tweets for a particular user (i.e. statuses/user_timeline) and it appears the count parameter doesn’t quite do what it is supposed to, chances are you’re calling an old version of the API that doesn’t support native retweets. A native retweet is a retweet that’s created by clicking the retweet button on the Twitter site, as opposed to using “RT”.

If the URL you’re using contains a call to <username>.json where <username> is the user you’re fetching tweets from, you’re using the old version. The new version is called user_timeline.json and instead takes the user via the user_id or screen_name query string parameter.

When using the old version, native retweets would be excluded in the result, but still count as a “hit”. This means that if the latest tweet from the user was a native retweet and you set the count to 1, you would get back nothing. The new API properly supports native retweets and includes them in the result.

It should be noted that in order for the result to include retweets (native or otherwise), you have to include the include_rts=true parameter in your query.

Post a Comment

Comments are moderated. Your email is never published nor shared.