Twitter API 1.1标签搜索

时间:2014-04-10 11:51:17

标签: php twitter hashtag

decodeI我正在尝试搜索包含php中某个标签的推文。我正在使用推荐的代码,但我一直没有得到任何结果。这是我用来尝试获取结果的代码。

$url = 'https://api.twitter.com/1.1/search/tweets.json';
$requestMethod = 'GET';
$getfield = '?q=#ManUtd&result_type=recent';

// Perform the request
$twitter = new TwitterAPIExchange($settings);
echo $twitter->setGetfield($getfield)
             ->buildOauth($url, $requestMethod)
             ->performRequest();

我也尝试过:

$url = 'https://api.twitter.com/1.1/search/tweets.json';
$requestMethod = 'GET';
$getfield = '?q=#ManUtd&result_type=recent';

// Perform the request
$twitter = new TwitterAPIExchange($settings);
$response = $twitter->setGetfield($getfield)
                    ->buildOauth($url, $requestMethod)
                    ->performRequest();
var_dump(json_decode($response));

我仍然得到相同的结果。任何人都知道为什么我从这个

中没有得到任何数据

1 个答案:

答案 0 :(得分:0)

如果您还没有找到答案,我建议您查看search endpoint上的dev.twitter.com页面。您可以使用twitter.com/search网络用户界面确认搜索字词的语法。 URL中搜索的结果将为您提供通过API搜索的正确编码。

正如Terence所说,你需要对哈希符号进行百分比编码(%23)。

因此,在通过Web界面进行搜索后,URL为:

https://twitter.com/search?q=%23ManUtd&src=typd

您希望查询包括:

%23ManUtd

查看Twitter guide on using the search endpoint