Twitterでハッシュタグが使用された回数の合計数を返す方法がわかりました。過去に私は働いていたが、その後 "http://search.twitter.com/search.json"というアドレスがTwitterによって引退したという次のコードを使用した。古いコードは:Twitter API 1.1ハッシュタグカウント
<?php
global $total, $hashtag;
//$hashtag = '#supportvisitbogor2011';
$hashtag = '#MyHashtag';
$total = 0;
function getTweets($hash_tag, $page) {
global $total, $hashtag;
$url = 'http://search.twitter.com/search.json?q='.urlencode($hash_tag).'&';
$url .= 'page='.$page;
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
$json = curl_exec ($ch);
curl_close ($ch);
//echo "<pre>";
//$json_decode = json_decode($json);
//print_r($json_decode->results);
$json_decode = json_decode($json);
$total += count($json_decode->results);
if($json_decode->next_page){
$temp = explode("&",$json_decode->next_page);
$p = explode("=",$temp[0]);
getTweets($hashtag,$p[1]);
}
}
getTweets($hashtag,1);
echo $total;
?>
私はあなたが認可されたツイッターアプリケーションを使用し、データを引き出すためにアクセスできることがわかっています。私は、アプリケーションを設定することができたと私は、次のコードを使用してデータのリストを取得することができますが、私はどのように合計カウントを思い付くためにそのデータを使用するか分からない。誰かが、私が持っているコードを変更するか、私がそれについてどうやってやるべきかを教えて、合計を得るのを手伝ってもらえますか?ここでハッシュタグのデータを引き出し、私が持っているコードです:
<?php
session_start();
require_once("twitteroauth.php"); //Path to twitteroauth library
$hashtag = "MyHashtag";
$consumerkey = "MYINFOWOULDBEHERE";
$consumersecret = "MYINFOWOULDBEHERE";
$accesstoken = "MYINFOWOULDBEHERE";
$accesstokensecret = "MYINFOWOULDBEHERE";
function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) {
$connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
return $connection;
}
$connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
$tweets = $connection->get("https://api.twitter.com/1.1/search/tweets.json?q=".$hashtag);
echo json_encode($tweets);
?>