Search code examples
ruby-on-railsrubytwitterrate-limiting

Twitter API bug - Tweets provides the wrong User_id. Work arounds?


I'm looking for a workaround to this Published Twitter API bug: http://code.google.com/p/twitter-api/issues/detail?id=214

When you fetch tweets, the tweet returns an incorrect User_id. However it does provide you with the correct Screen name.

My Goal is to use the API to do 2 things:

  1. Fetch all the followers of my twitter account, this is trivial with the ruby script: myfollowers = Twitter.follower_ids("justinzollars") (twitter gem) corresponding to this api call: https://dev.twitter.com/docs/api/1/get/followers/ids

  2. Save only tweets from an individual user. https://dev.twitter.com/docs/api/1/get/search

The problem is the first api call returns user_ids, and the tweets search call returns from_user_id_str (user_name). I don't want to make tens of thousands of api calls, asking twitter for the user_id of each from_user_id_str that is returned from the tweets search api call.

How can I efficiently solve this problem?


Solution

  • The Search API isn't really the best tool for the job as far as retrieving a specific user's tweets is concerned. You should use the User Timeline for that task, which doesn't suffer the Search API's mismatched user ID issue: https://dev.twitter.com/docs/api/1/get/statuses/user_timeline

    If you were using the Search API though, the most efficient pattern for converting screen names in Search to user ids on Twitter would be to use bulk user lookup, which would allow you to convert roughly 100 screen names to fully hydrated user objects (complete with the "real" user id): https://dev.twitter.com/docs/api/1/get/users/lookup