Twitter OAuth使用screen_name时无法对您进行身份验证

时间:2014-05-02 11:30:21

标签: twitter oauth

我有一个应用程序需要从用户那里获取收藏夹。如果我使用oauthdamnit设置它似乎工作正常:

$api = new OAuthDamnit(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_TOKEN_SECRET);

$raw = $api->get('https://api.twitter.com/1.1/favorites/list.json');
$response = json_decode($raw, true);
print_a ($response);

返回:

 Array
(
    [0] => Array
        (
            [created_at] => Mon Apr 14 19:32:26 +0000 2014
            [id] => 455790703126532096
            [id_str] => 455790703126532096
            [text] => Gmail put an update about Google+ straight ... etc

但我需要从其他用户那里获取它们 - 例如我添加?screen_name=YSL时:

此:

$api = new OAuthDamnit(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_TOKEN_SECRET);

$raw = $api->get('https://api.twitter.com/1.1/favorites/list.json?screen_name=YSL');
$response = json_decode($raw, true);
print_a ($response);

返回:

Array
(
    [errors] => Array
        (
            [0] => Array
                (
                    [message] => Could not authenticate you
                    [code] => 32
                )

        )

)

我做错了什么? https://dev.twitter.com/docs/api/1.1/get/favorites/list

2 个答案:

答案 0 :(得分:0)

API调用仅返回经过身份验证的用户的收藏夹,并且无法返回任意用户的数据,请参阅twitter API文档:

Returns the 20 most recent Tweets favorited by the authenticating or specified user.

来源:https://dev.twitter.com/docs/api/1.1/get/favorites/list

您必须获取正确的用户名和密码才能使此API调用正常工作。

答案 1 :(得分:0)

你在$api->get做错了。

如果你想通过GET请求将参数传递给url,那么在函数get中将它作为数组作为SECOND参数传递

$raw = $api->get('https://api.twitter.com/1.1/favorites/list.json',array('screen_name'=>'YSL'));

这是源代码,它表示自己将$params作为数组传递给第二个参数:

function get($url, $params = array()) {
     return $this->request('GET', $url, $params);
}

您可以在oauthdamnit.php行号39

中找到它