Zend_Service_Twitter 组件仍然适用于 Twitters API v1.0,它将在 2013 年 3 月 5 日弃用。所以我想让我的新网站准备好 Twitter API 交互 v1.1。v1.0 一切正常,但如果我将 URL 从 更改为/1/
失败/1.1/
,HTTP 标头代码 400 和 JSON 错误消息:(Bad Authentication data
代码:215)
为了让请求和访问令牌保持不变并且已经工作没有任何更改,但是如果我想验证这样的凭据,我会收到上面描述的错误:
// Take a look for the code here: http://framework.zend.com/manual/1.12/en/zend.oauth.introduction.html
$accessToken = $twitterAuth->getAccessToken($_GET, unserialize($_SESSION['TWITTER_REQUEST_TOKEN']));
// I have a valid access token and now the problematic part
$twitter = new Zend_Service_Twitter(array(
'username' => $accessToken->getParam('screen_name'),
'accessToken' => $accessToken
));
print_r($twitter->account->verifyCredentials());
我将 verifyCredentials 的代码Zend/Service/Twitter.php
从那个更改为:
public function accountVerifyCredentials()
{
$this->_init();
$response = $this->_get('/1/account/verify_credentials.xml');
return new Zend_Rest_Client_Result($response->getBody());
}
// to
public function accountVerifyCredentials()
{
$this->_init();
$response = $this->_get('/1.1/account/verify_credentials.json');
return Zend_Json::decode($response->getBody());
}
现在我在return Zend_Json[...]
这一行之前添加了:
print_r($this->_localHttpClient->getLastRequest());
// And I get this output of it:
GET /1.1/account/verify_credentials.json HTTP/1.1
Host: api.twitter.com
Connection: close
Accept-encoding: gzip, deflate
User-Agent: Zend_Http_Client
Accept-Charset: ISO-8859-1,utf-8
Authorization: OAuth realm="",oauth_consumer_key="",oauth_nonce="91b6160db351060cdf4c774c78e2d0f2",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1349107209",oauth_version="1.0",oauth_token="hereismytoken",oauth_signature="hereisavalidsignature"
正如你所看到的oauth_consumer_key
(realm
也)是空的。那可能是错误吗?我该如何解决这个错误(因为更严格的新 API 版本?)?以某种方式设置是否可以oauth_consumer_key
?如果是,我该如何管理?
编辑:我还发现了关于 Zend 框架问题跟踪器的错误报告:http: //framework.zend.com/issues/browse/ZF-12409(也许做一个赞成?)