Twitter Id and ID_str are different?



I’m making an api request to the followers/list endpoint.

I’m using a users id_str. And I was getting error code 34, “sorry that page does not exist”.
The docs basically enforce use of these id_str’s so I’ve been using them throughout the app like they’re the holy grail…

Now, on one of my requests it has two non matching ids.

What do I do about this…? :S


What language are you using? Some languages (eg Javascript) cannot deal with the large integers and so the Twitter API also passes them as strings. You should indeed use id_str in preference, because the language may otherwise scramble the ID, which is what I think you are seeing in the example here.


If you look at the printscreen, you can see the two ids are very similar, but are different, the only differences being that “392” at the end of the id_str is “400” on the id.

I know about this problem with different languages, thats why I defaulted to always use the id_str everywhere, because I am using PHP and JavaScript.

This isnt a problem like this though, as this is a direct response from your api in PHP.


It doesn’t appear to be an issue with the integer being too large but it is a rather strange issue. What endpoint/request data gave you that response?


Glad you noticed that^^

This happens when I do followers/list followers/create and such. The original response itself is from the followers/list endpoint.


So, you are using followers/list to get a list of ids and then using followers/create on some of those ids. One errored and then you called another endpoint to get the output in the image from the first post, right? What was the endpoint that gave that result?


Sorry my bad, the “original data” is from the search endpoint: users/search

We are then displaying a list of them users, which can be followed via the followers/create endpoint(this errors, not with every user though)

We also have a button to load that users followers also, with the followers/list endpoint, which returns an array of user and which also errors(but not for all users).

The output in the image, is from the original data, using the users/search endpoint


Last question for now, what programming language?


PHP Server side to do api requests, and then I’m passing this data to JavaScript on the front end


I believe that your code (or the library it is calling) is munging the integer.

$ twurl "/1.1/users/show.json?id=716448393808187392"
  "id": 716448393808187392,
  "id_str": "716448393808187392",

As you can see, calling the API directly using twurl returns matching values for id and id_str for this user.


I ran into this when storing the id in ruby and fetching it via AJAX with javascript. However, Twitter’s IDs are too large for JavaScript integers and thus you are better off using the id_str both for storing in the database and especially for anything related to javascript. Currently I still store using BIGINT’s but I convert to a string before passing data to the JS side.

Using a string also has the benefit of guaranteeing that you will never have to change your database column if it doesn’t fit anymore due to size.