2015-10-19 70 views
0

我遇到了Twitter搜索API的問題。我試圖抓住用戶給出的100個最受歡迎的推文的轉推總量。Twitter搜索API - 熱門tweet無法正常工作

我正試圖用此代碼實現此目的。

<?php 
    //Debugging 
    ini_set('display_errors', 'On'); 
    error_reporting(E_ALL); 

    //Include Tokens file 
    require_once('tokens.php'); 
    //Include Auth lib 
    require_once('twitterAuth/TwitterAPIExchange.php'); 

    //Grab subject from url 
    $subject = $_GET["subject"]; 

    //Request 
    $url = 'https://api.twitter.com/1.1/search/tweets.json'; 
    $getfield = '?q='.$subject.'&count=100&result_type=popular'; 
    $requestMethod = 'GET'; 
    $twitter = new TwitterAPIExchange($settings); 
    $result = $twitter->setGetfield($getfield) 
      ->buildOauth($url, $requestMethod) 
      ->performRequest(); 

     $json_output = json_decode($result, true); //getting the file content as array 
     $count = 0; 
     $total = 0; 
     foreach($json_output['statuses'] as $tweets) { 
      $count = intval($tweets['retweet_count']); 
      $total = $total + $count; 
     } 
     echo '{"data":[{"retweet_count":'.$total.'}]}'; 
?> 

雖然當我使用的result_type =混合的result_type =最近,它會因爲某些原因,而不是當我將其更改爲result_type的工作=流行偶數雖然這段代碼是偉大的工作Twitter API已在其文檔中列爲選項。 Twitter Search API documentation。運行請求時它不會返回任何錯誤,但不會顯示任何反饋。當我用混合或近代替代流行時,代碼的工作非常出色。一直堅持這一點,幫助將不勝感激!提前致謝!

回答