php – 无法从令牌URL Twitter API检索有效的令牌响应
作者:互联网
我在我的zend框架应用程序中使用twitter进行登录.但在从twitter进行身份验证后,它显示以下错误:
Message:Could not retrieve a valid Token response from Token URL: /oauth/access_token?oauth_consumer_key=xxxxxxxxxxxxxxx&oauth_nonce=xxxxxxxxxxxxxxxxxxxx&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1352270857&oauth_token=xxxxxxxxxxxxx&oauth_version=1.0
&oauth_verifier=xxxxxxxxxxxxxxxxxxxxx&oauth_signature=wv5gdop77NA9BeZI7ilQcEFsqGH8CeR4%3D Invalid / expired Token
以下是我的代码:
public function twittercallbackAction() {
$path = realpath(APPLICATION_PATH . '/../library/');
set_include_path($path);
$config = array(
"callbackUrl" => "http://" . $_SERVER['HTTP_HOST'] . "/register/twittercallback",
"siteUrl" => "http://twitter.com/oauth",
"consumerKey" => "xxxxxxxxxxxxxx",
"consumerSecret" => "xxxxxxxxxxxxxxxxxxxx"
);
$consumer = new Zend_Oauth_Consumer($config);
if (!empty($_GET) && isset($_SESSION['TWITTER_REQUEST_TOKEN'])) {
$token = $consumer->getAccessToken($_GET, unserialize($_SESSION['TWITTER_REQUEST_TOKEN']));
// Now that we have an Access Token, we can discard the Request Token
// get users timeline
// $_SESSION['TWITTER_REQUEST_TOKEN'] = null;
} else {
// Mistaken request? Some malfeasant trying something?
exit('Invalid callback request. Oops. Sorry.');
}
}
我在谷歌上搜索这个问题,但没有得到任何解决方案.
我该如何处理这个问题.
谢谢
解决方法:
我测试了你的代码,我假设你从http://framework.zend.com/manual/1.12/en/zend.oauth.introduction.html开始,它运行正常.以下是一些要检查的事项:
>您的消费者应用密钥/秘密是否有效?
>您的服务器是否设置了正确的日期/时间?
>生成请求令牌的代码是什么?
标签:php,twitter,zend-framework,twitter-oauth 来源: https://codeday.me/bug/20190826/1725671.html