来自亚伯拉罕的php twitteroauth错误代码32获取用户身份验证的用户界面

时间:2018-02-21 11:02:54

标签: php twitter-oauth

我想获取用户身份验证访问令牌来访问他的个人资料信息。当我运行脚本时,它抛出以下错误

  

致命错误:未捕获的异常' Abraham \ TwitterOAuth \ TwitterOAuthException'有消息' {"错误":[{"代码":32,"消息":"无法对您进行身份验证。&#34 ;}]}'   在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']
    ]
 );

1 个答案:

答案 0 :(得分:0)

我设置了twitter应用程序的重定向网址,这解决了我的代码32问题