【发布时间】:2018-02-27 18:18:08
【问题描述】:
我想获取用户身份验证访问令牌来访问他的个人资料信息。当我运行脚本时,它抛出了以下错误
致命错误:未捕获的异常 'Abraham\TwitterOAuth\TwitterOAuthException' 带有消息 '{"errors":[{"code":32,"message":"Could not authenticate you."}]}' 在 C:\xampp\htdocs\promo\app\twitteroauth\src\TwitterOAuth.php:138
我的代码是
$twitteroauth = new TwitterOAuth($config['consumer_key'],
$config['consumer_secret']);
//request token of application
$request_token = $twitteroauth->oauth(
'oauth/request_token', [
'oauth_callback' => $config['url_callback']
]
);
// throw exception if something gone wrong
if ($twitteroauth->getLastHttpCode() != 200) {
throw new \Exception('There was a problem performing this request');
}
// save token of application to session
$_SESSION['oauth_token'] = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
// generate the URL to make request to authorize our application
$url = $twitteroauth->url(
'oauth/authorize', [
'oauth_token' => $request_token['oauth_token']
]
);
// and redirect
header('Location: ' . $url);
请告诉我如何解决该错误。根据我的发现,当以下函数通过上述异常调用它时。
// request token of application
$request_token = $twitteroauth->oauth(
'oauth/request_token', [
'oauth_callback' => $config['url_callback']
]
);
【问题讨论】:
标签: php twitter-oauth