Ho riscontrato un problema che spiega come restituire un conteggio totale per il numero di volte in cui è stato utilizzato un hashtag su Twitter. In passato ho usato il seguente codice che funzionava ma l'indirizzo "http://search.twitter.com/search.json" è stato ritirato da Twitter. Il vecchio codice era:Numero di hashtag dell'API di Twitter 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;
?>
io so che tu sai essere necessario utilizzare un applicazione Twitter autorizzato e avere accesso ad essere in grado di estrarre i dati. Sono stato in grado di configurare l'app e posso estrarre un elenco di dati utilizzando il seguente codice, ma non sono sicuro di come utilizzare tali dati per ottenere un conteggio totale. Qualcuno può aiutarmi a ottenere un totale cambiando il codice che ho o aiutandomi a come dovrei farlo. Ecco il codice che ho che tira i dati hashtag:
<?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);
?>