使用 CURL 仅获取最新推文的 ID


Getting only the ID of latest tweet using CURL

$ch = curl_init("http://api.twitter.com/1/statuses/user_timeline/nafhameducation.json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$latest_tweet = curl_exec($ch);
$latest_tweet_id = $latest_tweet[0]->id_str;
curl_close($ch);

我正在使用此代码在我的时间线上获取最新推文的 ID,但是 $latest_tweet_id 返回一个空字符串,知道为什么它没有得到我需要的东西吗?

尝试

 $latest_tweet = json_decode(curl_exec($ch));

卷曲返回文本。 打开你的错误报告,顺便说一句,你应该得到PHP错误,试图访问字符串作为对象。

此外,在调试时,在第 3 行之后var_dump($latest_tweet);会很有用——这应该清楚地表明 $latest_tweet 的类型不是对象。