Why is the wrong tweet id returned from the twitter API?

I use the twitter API to get custom tweets on the home page. I am using json response format. Recently, the tweet identifier (in the API, it's just β€œid”) was not reconfigured correctly. As an example

usually it should be returned as follows: "id": 14057503720, (example from the Twitter console) however, at my request, it returns as follows: "id": 1172601832

This is 1 digit less, and it is completely different. I need the correct identifier because I cannot use parameters like from_id or max_id.

+5
source share
3 answers

id_str id. , , , JSON, , id_str - , .

+5

1 , . , , from_id max_id.

; . ,

0x345E47BE8
 0x45E47BE8

Tweet 64- - 32- . id_str, ( ).

+2

,

$url = "http://search.twitter.com/search.json?q=QUERY"; //<--- replace the word QUERY for your own query 
$data = get_data($url);
$obj = json_decode($data);

function get_data($url){
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
    }

foreach ($obj->results as $item){
    $text = $item->text;
    $user = $item-> from_user;
    $img = $item->profile_image_url;
    $tweetId = $item->id_str;  // <--- On this line we are getting the ID of the tweet

echo ' @';  
echo $user;
echo $text;
echo 'Tweet ID: '. $tweetId; //<-- On this line we display the ID of the tweet

GET search | Twitter

The example query in line 30 shows "id_str":"122032448266698752" and this is the reason for using $tweetId = $item->id_str; to getid_str

+1
source

All Articles