来自亚伯拉罕的TwitterOAuth - 无法验证你;错误:32

时间:2015-03-05 17:06:45

标签: php authentication twitter oauth twitter-oauth

我正在尝试使用亚伯拉罕的TwitterOAuth解决方案。

我已按照他的文档中所述完成了所有操作,但我仍然遇到了错误:

{“errors”:[{“code”:32,“message”:“无法验证您。”}}}

这是我的源代码:

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

所有钥匙都是正确的。我不知道为什么这仍然会发生。 应用程序权限是只读的。

我想要做的是根据搜索查询获取推文。

你知道如何解决这个问题吗?如果您需要更多信息,请与我们联系。

1 个答案:

答案 0 :(得分:2)

希望这能解决你的问题......

<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

TwitterOAuth对象

$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