Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
859 views
in Technique[技术] by (71.8m points)

api - Telling Whether A Tweet Is A Retweet Or Not?

I'm using the Twitter API in order to pull tweets from specific users. I have it working exactly as I want, except for being able to tell whether or not a specific tweet is original from the user or if it is a retweet.

I'm using the following call: https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=philiprucker&count=1

When looking at the results, it appears that I should be able to pull retweeted from the results and it should return true or false. However, this is only returning the string retweet.

$url = "http://api.twitter.com/1/statuses/user_timeline.xml?include_entities=true&include_rts=true&screen_name=$screen_name&count=200" ;
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
$xml = curl_exec ($ch);
curl_close ($ch);

$twelement = new SimpleXMLElement($xml);
foreach ($twelement->status as $status) {
    $text = dbEscape(trim($status->text));
    $time = strtotime($status->created_at);
    $id = $status->id;
    $num_retweets = $status->retweet_count;
    $retweet = $status->retweeted;
    dbQuery("INSERT INTO `twitter` (`id`,`screen_name`,`time`,`text`,`hidden`, `numRetweets`, `retweet`) VALUES ('$id','$screen_name','$time','$text','n','$num_retweets','retweet')");
    // dbQuery("INSERT INTO `twitter` (`id`,`screen_name`,`time`,`text`,`hidden`) VALUES ('$id','$screen_name','$time','$text','n')");
}

This is the code doing what I describe. I believe all the relevant code is there. Any help would be greatly appreciated!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are specifically putting the string retweet into the table, not the value of $retweet.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...