Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why a wrong tweet id is returned from twitter API?

Tags:

json

twitter

api

I use twitter API to retrieve the user home timeline tweets. I use json response format. Recently the tweet id (in API it is just 'id') are retuned wrong. As an example

normally it should return like this: "id": 14057503720, (example is from twitter console) however at my request it is returned like this: "id": 1172601832

It is 1 digit less and it is totally different. I need the proper ID because I can't make use of the parameters like since_id or max_id.

like image 743
Ömer Faruk Gül Avatar asked May 15 '10 20:05

Ömer Faruk Gül


People also ask

Why is Twitter API not working?

There was a problem authenticating your request. This could be due to missing or incorrect authentication credentials. This may also be returned in other undefined circumstances. Check that you are using the correct authentication method and that your credentials are correct.

What does the Twitter API return?

All Twitter APIs that return Tweets provide that data encoded using JavaScript Object Notation (JSON). JSON is based on key-value pairs, with named attributes and associated values. These attributes, and their state are used to describe objects. At Twitter we serve many objects as JSON, including Tweets and Users.

What is ID in Twitter API?

Today, Twitter IDs are unique 64-bit unsigned integers, which are based on time, instead of being sequential. The full ID is composed of a timestamp, a worker number, and a sequence number.

Can you get old tweets from Twitter API?

Both Historical PowerTrack and Full-Archive Search provide access to any publicly available Tweet, starting with the first Tweet from March 2006. Deciding which product better suits your use case can be key in getting the data you want when you need it.


2 Answers

Use id_str instead of id. It doesn't seem to be documented, but if you look at the raw source of the JSON you can see that id_str for each tweet is the one that correctly corresponds to the ID of the tweet.

like image 133
Carolyn Avatar answered Sep 19 '22 07:09

Carolyn


It is 1 digit less and it is totally different. I need the proper ID because I can't make use of the parameters like since_id or max_id.

It is not totally different; just different. If you write both IDs in hex, you'll receive

0x345E47BE8
 0x45E47BE8

Tweet IDs are 64-bit and somewhere in parsing you lose the most significant 32-bit half of it. Use id_str as other (also in the linked article) suggest.

like image 38
pwes Avatar answered Sep 17 '22 07:09

pwes