Twitter API surfacing incorrect "join date(s)" and user IDs


#1

I’m working on app that will surface when a particular user joined Twitter (very similar to the semi-defunct whendidyoujointwitter.com)

The issue I’m having is when searching for some usernames, I’m being presented with inaccurate data. Namely, if I search for a particular username the API gives me one thing, yet if I were to go to Twitter.com and search for the same user it would give me an entirely different result (the one on Twitter is always the correct info).

It works perfectly for some, yet is entirely wrong for others- examples below.

Any thoughts as to why I might be encountering this?


when in reality, the join date is

and this

when in reality, the join date is


#2

This is odd. Which API endpoint are you calling? For the user @bar, I get back a totally different id, and the correct created_at date matching the web page. What is the logic of your code doing in this case?

twurl "/1.1/users/show.json?screen_name=bar"

{
  "id": 2530071,
  "id_str": "2530071",
  "name": "mr bar",
  "screen_name": "bar",
  "location": "",
  "description": "",
  "url": null,
  "entities": {
    "description": {
      "urls": [

      ]
    }
  },
  "protected": false,
  "followers_count": 433,
  "friends_count": 1,
  "listed_count": 10,
  "created_at": "Tue Mar 27 17:48:24 +0000 2007",
  "favourites_count": 0,
  "utc_offset": -36000,
  "time_zone": "Hawaii",
  "geo_enabled": false,
  "verified": false,
  "statuses_count": 3,
  "lang": "en",
  "status": {
    "created_at": "Sat Jan 23 02:55:21 +0000 2010",
    "id": 8096174063,
    "id_str": "8096174063",
    "text": "I nominate @dothesit for a Shorty Award in #snoobab because... he will build a better baboon http://bit.ly/shorty",
    "source": "<a href=\"http://shortyawards.com\" rel=\"nofollow\">Shorty Awards</a>",
    "truncated": false,
    "in_reply_to_status_id": null,
    "in_reply_to_status_id_str": null,
    "in_reply_to_user_id": null,
    "in_reply_to_user_id_str": null,
    "in_reply_to_screen_name": null,
    "geo": null,
    "coordinates": null,
    "place": null,
    "contributors": null,
    "retweet_count": 15,
    "favorite_count": 53,
    "entities": {
      "hashtags": [
        {
          "text": "snoobab",
          "indices": [
            43,
            51
          ]
        }
      ],
      "symbols": [

      ],
      "urls": [

      ],
      "user_mentions": [
        {
          "screen_name": "DoTheSit",
          "name": "Dan",
          "id": 20647729,
          "id_str": "20647729",
          "indices": [
            11,
            20
          ]
        }
      ]
    },
    "favorited": false,
    "retweeted": false,
    "lang": "en"
  },
  "contributors_enabled": false,
  "is_translator": false,
  "is_translation_enabled": false,
  "profile_background_color": "1A1B1F",
  "profile_background_image_url": "http://abs.twimg.com/images/themes/theme9/bg.gif",
  "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme9/bg.gif",
  "profile_background_tile": false,
  "profile_image_url": "http://abs.twimg.com/sticky/default_profile_images/default_profile_5_normal.png",
  "profile_image_url_https": "https://abs.twimg.com/sticky/default_profile_images/default_profile_5_normal.png",
  "profile_link_color": "2FC2EF",
  "profile_sidebar_border_color": "181A1E",
  "profile_sidebar_fill_color": "252429",
  "profile_text_color": "666666",
  "profile_use_background_image": true,
  "default_profile": false,
  "default_profile_image": true,
  "following": false,
  "follow_request_sent": false,
  "notifications": false
}

#3

Agreed- it is odd. I am coding it using Rails, and thus rather than directly using Twitter’s API, I’m using the “Twitter Gem” (which to the best of my knowledge is the same thing: the gem just subsumes all of the API’s functionality)

Heres’s my code which is making the API calls:

def search_results
twitter_client = Twitter::REST::Client.new do |config|
config.consumer_key = ENV[‘twitter_consumer_key’]
config.consumer_secret = ENV[‘twitter_consumer_secret’]
config.access_token = ENV[‘twitter_access_token’]
config.access_token_secret = ENV[‘twitter_access_token_secret’]
end

@name = params[:name]
user = twitter_client.user_search(@name).first
if user
 @full_name = user.name
 @created_at = user.created_at    
 @user_id = user.id
else
  render "welcome/error"
end

end

In case you’d like to see the current code and run it locally/ on localhost using Rails, here’s a link to the GitHub repository.


Thanks!


#4

I suspect this is using the Search API, not the user lookup endpoint.
checks code for Twitter gem
… Yup. Your code is doing a search, and getting back the first user it matches, not necessarily the exact name.

 def user_search(query, options = {})
     perform_with_objects(:get, '/1.1/users/search.json', options.merge(:q => query), Twitter::User)

So we want the API call that hits users/show.json… which I believe is going to be twitter_client.user. Take a look at that (defined in users.rb in the gem FWIW).


#5

Fantastic diagnosis- that’s exactly what it was, and now works like a charm.
Thanks a lot Andy!!