简体   繁体   English

Twitter API 1.1主题标签搜索

[英]Twitter API 1.1 hashtag search

decodeI am trying to search for tweets that contain a certain hashtag in php. 我正在尝试搜索在PHP中包含特定标签的推文。 i am using the recommended code but I just keep getting no results back from it. 我正在使用推荐的代码,但我一直没有得到任何结果。 This is the code I am using to try and get the results. 这是我用来尝试获得结果的代码。

$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();

I have also tried: 我也尝试过:

$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));

And I still get the same results. 而且我仍然得到相同的结果。 Anybody know why i am getting no data back from this 有人知道为什么我没有从这里得到任何数据

If you haven't already found the answer to this, I'd suggest taking a look at the dev.twitter.com page on the search endpoint . 如果您还没有找到答案,建议您浏览一下搜索端点上的dev.twitter.com页面。 You can confirm the syntax for a search term by using the twitter.com/search web UI. 您可以使用twitter.com/search Web UI确认搜索词的语法。 The outcome of that search in the URL will give you the correct encoding for your search via the API. URL中的搜索结果将为您提供通过API进行搜索的正确编码。

As Terence noted, you do need to percent-encode the hash symbol (%23). 正如Terence所指出的,您确实需要对哈希符号(%23)进行百分比编码。

So, after a search via the web interface, the URL is: 因此,通过网络界面搜索后,URL为:

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

You'd want your query to include: 您希望查询包括:

%23ManUtd

Check out the Twitter guide on using the search endpoint . 查看有关使用搜索端点Twitter指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM