Search code examples
twitter

Twitter GET statuses/user_timeline returning too few records


On the news page of our website, we use Twitter's GET statuses/user_timeline API endpoint to pull in 4 tweets for every Ajax page of 8 news stories that we show, making 4 rows of 3 links in the results grid. This works fine for the first 8 pages (which takes us back just over a month from now in terms of tweets). But then when I get to the API call to fetch 36 tweets for page 9 and 40 tweets for page 10, it only returns 35 and 38 tweets.

I think this might be down to this issue that David Yell mentioned in his answer here, with the search API not returning tweets that it considers low quality or something. If I go to the timeline of our corporate Twitter account, I can see the specific tweets that are being omitted — I don'think they're necessarily spammy or low-quality, one has 47 interactions (21 RTs, 22 Likes and 4 replies) and another has 12 such interactions, so it's not like they're tweets that just went out echoing into the void, but sure, maybe the algorithm disagrees or whatever.

The API calls are effectively identical throughout; if I log the API call URL from my (bespoke C#) code involved and the number of tweets in the returned JSON, it is as simple as https://api.twitter.com/1.1/statuses/user_timeline.json?count=36&screen_name=[redacted]&exclude_replies=1&tweet_mode=extended returning only 35 tweets and …/statuses/user_timeline.json?count=40&… returning only 38, so it doesn't seem like there's anything wrong with the API calls per se, especially given the previous 8 calls all have the right number of tweets (so ?count=32… having 32 tweets in the JSON response and so on.) I know we have made more tweets since the QA analyst spotted this earlier in the week and the shape of the "missing" entries in the results grid has stayed consistent, but we hadn't got far enough in debugging until today to be able to confirm if it's the same tweets that were missing or not.

Does anyone have any experience of persuading the API to return those "missing" tweets? Or do I have to work out how to record and pass in the amended offset, to ensure I still end up with even pages of 4×3 in the results grid, without gaps? (Or something.)


Solution

  • Some applications use count to fetch a number of entries and if the available amount is below then it fills null or returns an array short of the target number.

    In this case, Twitter has detailed count means "best thought of as a limit to the number of Tweets to return because suspended or deleted content is removed after the count has been applied.".

    Twitter also notes that the count includes retweets even if include_rts is not supplied.

    https://developer.twitter.com/en/docs/twitter-api/v1/tweets/timelines/api-reference/get-statuses-user_timeline