【问题标题】:Twitter API 1.1 hashtag searchTwitter API 1.1 标签搜索
【发布时间】:2014-05-24 02:39:13
【问题描述】:

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

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

我仍然得到相同的结果。任何人都知道为什么我没有从中得到任何数据

【问题讨论】:

  • 您确定您的$settings 正确吗?您是否尝试过不带标签搜索 ManUtd(我不确定这是否会造成问题)
  • 是的,$settings 与我用于其他事情的设置相同,它们都可以工作。我在 TwitterAPIExchange 中没有碰过任何东西,但我猜这一切都是正确的
  • 当您对 # 进行 URL 编码时会发生什么情况,所以它是 %23
  • 当我使用 $getfield = '?q=%23ManUtd&result_type=recent';
  • 嗯,只需先进行常规调试,然后了解您的问题。 blog.teamtreehouse.com/how-to-debug-in-php

标签: php twitter hashtag


【解决方案1】:

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

正如 Terence 所说,您确实需要对井号 (%23) 进行百分比编码。

所以,通过网页界面搜索后,网址是:

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

您希望您的查询包括:

%23ManUtd

查看Twitter guide on using the search endpoint

【讨论】:

    猜你喜欢
    • 2012-10-21
    • 2013-06-26
    • 2013-06-11
    • 2018-10-13
    • 1970-01-01
    • 1970-01-01
    • 2012-11-30
    • 1970-01-01
    • 2013-06-10
    相关资源
    最近更新 更多