2015-10-19 108 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。运行请求时它不会返回任何错误,但不会显示任何反馈。当我用混合或近代替代流行时,代码的工作非常出色。一直坚持这一点,帮助将不胜感激!提前致谢!

回答