从twitter PHP获取特定hashtag的计数

从twitter PHP获取特定hashtag的计数,php,api,curl,twitter,simplexml,Php,Api,Curl,Twitter,Simplexml,我能够用PHP获得特定标签的所有twitter帖子。现在,我想得到这个特定标签的总计数。 我正在使用curl、simplexmlement以及twitterapi搜索调用。 你知道如何获取特定标签的总计数吗 <?php $pagetitle = "Pull Twitter Hashtags"; function getTweets($hash_tag) { $url = 'http://search.twitter.com/search.atom?q='.urlencode(

我能够用PHP获得特定标签的所有twitter帖子。现在,我想得到这个特定标签的总计数。 我正在使用curl、simplexmlement以及twitterapi搜索调用。 你知道如何获取特定标签的总计数吗

<?php
$pagetitle = "Pull Twitter Hashtags";


function getTweets($hash_tag) {

    $url = 'http://search.twitter.com/search.atom?q='.urlencode($hash_tag).'&result_type=recent' ;
    echo "<p>Connecting to <strong>$url</strong> ...</p>";
    $ch = curl_init($url);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $xml = curl_exec ($ch);
    curl_close ($ch);

//If you want to see the response from Twitter, uncomment this next part out:
//echo "<p>Response:</p>";
//echo "<pre>".htmlspecialchars($xml)."</pre>";

    $affected = 0;
    $twelement = new SimpleXMLElement($xml);
    foreach ($twelement->entry as $entry) {
    $text = trim($entry->title);
    $author = trim($entry->author->name);
    $time = strtotime($entry->published);
    $id = $entry->id;

    //echo count($entry->text);
    echo "<p>Tweet from ".$author.": <strong>".$text."</strong>  <em>Posted ".date('n/j/y g:i a',$time)."</em></p>";
}



return true ;
}

getTweets('#converse');


?>

使用

使用

没有“所有推文”这样的东西——只有“过去x小时(可能是几天)内的所有推文”

<>这是任何推特开发者应该知道的第一件事——考虑推特无限流。你不能数一条无限的溪流,也不能得到所有的溪流

要计算“过去一小时内所有关于#hashtag的推文”,只需获取过去一小时内所有带有该hashtag的推文,然后计算它们。

没有“所有推文”这样的东西,只有“过去x小时内(可能是几天)的所有推文”

<>这是任何推特开发者应该知道的第一件事——考虑推特无限流。你不能数一条无限的溪流,也不能得到所有的溪流

要计算“过去一小时内所有关于#hashtag的推文”,只需获取过去一小时内所有带有该hashtag的推文,然后进行计数

$number_of_tweets = count($twelement->entry);