猿问

使用推特资产交换按日期搜索推文

我正在尝试使用推特apiexchange包装器搜索给定日期范围内的推文。


这是我的代码


require_once('TwitterAPIExchange.php');

$settings = array(

'oauth_access_token' => "xx",

'oauth_access_token_secret' => "xx",

'consumer_key' => "xx",

'consumer_secret' => "xx"

);


$url = "https://api.twitter.com/1.1/search/tweets.json";


$requestMethod = "GET"


$getfield = "?q=from:manutd&until:2018-01-20&since:2018-01-01";

$twitter = new TwitterAPIExchange($settings);

$string = json_decode($twitter->setGetfield($getfield)

->buildOauth($url, $requestMethod)

->performRequest(),$assoc = TRUE);

if(array_key_exists("errors", $string)) {echo "<h3>Sorry, there was a problem.</h3> 

  <p>Twitter returned the following error message:</p><p><em>".$string[errors][0] 

  ["message"]."</em></p>";exit();}

  foreach($string as $items)

  {



    echo "Time and Date of Tweet: ".$items['created_at']."<br />";

    echo "Tweet: ". $items['full_text']."<br />";

    echo "Tweeted by: ". $items['user']['name']."<br />";

    echo "Screen name: ". $items['user']['screen_name']."<br />";

    echo "Followers: ". $items['user']['followers_count']."<br />";

    echo "Friends: ". $items['user']['friends_count']."<br />";

    echo "Listed: ". $items['user']['listed_count']."<br /><hr />";




   }

这将返回来自指定用户的最新推文,日期字段似乎被忽略。


是否可以使用 API 按日期搜索?


慕娘9325324
浏览 106回答 1
1回答

哈士奇WWW

搜索 API 支持此功能,但您必须像这样组合查询:https://api.twitter.com/1.1/search/tweets.json?q=from%3Atwitterdev&result_type=mixed&count=2参考:https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets上面的查询字符串是以下网址编码形式:所以你会通过像https://api.twitter.com/1.1/search/tweets.json?q=%3Afrom:manutd&until:2018-01-20&since:2018-01-01搜索运算符列表可在此处找到。
随时随地看视频慕课网APP
我要回答