OAuth PHP lib - Twitter令牌请求失败

时间:2011-07-05 20:41:22

标签: php oauth twitter-oauth

我正在尝试使用此PHP库从Twitter请求令牌:http://oauth.googlecode.com/svn/code/php/但它不起作用,我得到“无法验证oauth签名和令牌”。

我的代码:

//http://oauth.googlecode.com/svn/code/php/OAuth.php
require 'OAuth.php';

$key = 'XXXXXX';
$secret = 'XXXXXX';
$consumer = new OAuthConsumer($key, $secret);
$sig_method = new OAuthSignatureMethod_HMAC_SHA1;

$api_endpoint = 'https://api.twitter.com/oauth/request_token';

$parameters = array('oauth_callback'=>'oob');

$req = OAuthRequest::from_consumer_and_token($consumer, null, "POST", $api_endpoint, $parameters);
$sig_method = new OAuthSignatureMethod_HMAC_SHA1();
$req->sign_request($sig_method, $consumer, null);

$ch = curl_init($req->to_url());
curl_exec($ch);
curl_close($ch);

1 个答案:

答案 0 :(得分:0)

看起来您需要将request_token调用作为GET请求而不是POST:

$req = OAuthRequest::from_consumer_and_token($consumer, null, "GET", $api_endpoint, $parameters);

我对此进行了测试,似乎可以从我自己的应用程序中获取令牌。

您还可以查看亚伯拉罕的Twitter OAuth库,使实施变得更加轻松。

https://github.com/abraham/twitteroauth

相关问题