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));
我仍然得到同样的结果。任何人都知道为什么我没有从这个中得到任何数据
如果您还没有找到答案,我建议您查看搜索端点上的dev.twitter.com页面。您可以使用twitter.com/search web UI确认搜索词的语法。URL中的搜索结果将通过API为您的搜索提供正确的编码。
正如Terence所指出的,您确实需要对哈希符号(%23)进行百分比编码。
因此,通过网络界面搜索后,URL为:
https://twitter.com/search?q=%23ManUtd&src=typd
您希望您的查询包括:
%23ManUtd
查看有关使用搜索端点的Twitter指南。