我正在尝试使用Abraham的TwitterOAuth解决方案。
我已经按照他的文档中的描述做了所有的事情,但我仍然会收到错误:
{"错误":〔{"代码":32,"消息":"无法验证您的身份。"}〕}
这是我的源代码:
require "twitteroauth/autoload.php";
use Abraham'TwitterOAuth'TwitterOAuth;
$consumerkey = 'xx';
$consumersecret = 'xx';
$accesstoken = 'xx';
$accesstokensecret = 'xx';
$connection = new TwitterOAuth($consumerkey,$consumersecret,$accesstoken,$accesstokensecret);
$tweets = $connection->get("search/tweets.json?q=superbowl");
echo json_encode($tweets);
所有钥匙都是正确的。我不知道为什么这种情况还会发生。应用程序权限为只读。
我想做的是基于搜索查询获取推文。
你知道怎么解决这个问题吗?如果你需要更多信息,请告诉我。
希望这能解决您的问题。。。。
<form action='' method='get' ><input type='text' name='q'> <button type='submit' >click</button></form>
<?php
require "autoload.php";
use Abraham'TwitterOAuth'TwitterOAuth;
$consumerKey = "youconsumerkey";
$consumerSecret = "yourconsumersecretkey";
$oauthToken = "youoauthtoken";
$oauthTokenSecret = "youroauthtokensecret";
$twitter = new TwitterOAuth($consumerKey,$consumerSecret,$oauthToken,$oauthTokenSecret);
$search = isset($_GET['q']);
if(isset($_GET['q'])){
$tweets = $twitter->get('search/tweets',array('q'=>'%23'.$_GET['q'],'result_type'=>'recent','count'=>'10'));
//var_dump($tweets);
foreach($tweets->statuses as $value){
echo $value->user->name; echo "<br/>";
//echo json_encode($tweets);
}
}
?>
#事实上,在我的情况下,背后的原因]无法验证您的身份;错误:32]
这是我为我的项目测试的代码行吗:
// $tweets = $twitter->get('search/tweets.json?q=mytest&result_type=recent&count=10');
我正在使用TwitterOAuth PHP库用于Twitter REST API,https://twitteroauth.com/。
HTTP得到https://api.twitter.com/1.1/search/tweets.json
推特OAuth
$tweets= $twitter->get("search/tweets.json", array("result_type" => 'recent', "count" => 10)); //should be like this
// $tweets= $twitter->get('search/tweets.json?q=mi_twitter_test&result_type=recent&count=10'); //throws authentication error