Zend_Service_Twitter Oauth签名不正确

时间:2010-08-26 14:50:08

标签: php zend-framework twitter

我使用Zend_Oauth_Consumer成功连接到Twitter并获得了访问令牌,但是当我尝试使用此访问令牌时,我收到了错误。

这是代码:

$token = unserialize($twsession->access_token); # would be in DB
$twitter = new Zend_Service_Twitter(array(
    'username' => $token->screen_name,
    'accessToken' => $token
));
$response = $twitter->account->verifyCredentials();

输出:

Zend_Rest_Client_Result Object (
    [_sxml:protected] => SimpleXMLElement Object
        (
            [request] => /1/account/verify_credentials.xml
            [error] => Incorrect signature
        )

    [_errstr:protected] =>  )

我认为代码实际上是正确的,很难说ZF网站上的示例是不完整的。

FWIW我正在使用Zend Framework 1.10.8

1 个答案:

答案 0 :(得分:3)

某些字段丢失了:

$token = unserialize($twsession->access_token); # would be in DB
$twitter = new Zend_Service_Twitter(array(
    'username' => $token->screen_name,
    'accessToken' => $token
));
$response = $twitter->account->verifyCredentials();

应该是:

$token = unserialize($twsession->access_token); # would be in DB
$twitter = new Zend_Service_Twitter(array(
     'username' => $token->screen_name,
     'accessToken' => $token,
     'consumerKey' => YOUR_APP_CONSUMER_KEY,
     'consumerSecret' => YOUR_APP_CONSUMER_SECRET,
     'callbackUrl' => YOUR_CALLBACK_URL
 ));
$response = $twitter->account->verifyCredentials();

要确认,对于有效签名,您需要与Zend_Oauth_Consumer

一起使用的所有相同字段