我正在使用twitter,并且在twitter上遇到问题,要求我授权应用程序的使用,即使我已经授权了应用程序。例如,我授权应用程序的使用,注销,然后转到twitter登录,它再次要求我授权应用程序的使用。注意,我的问题是让我授权应用程序,而不是我想象的认证区域,一旦授权问题得到解决,twitter的身份验证就会奏效。
流动应是:
1./用户授权使用twitter。
2./ Twitter发送回拨
3./回调执行数据库交互以保存用户并与应用程序对用户进行身份验证
4./回调重定向至主页
5./用户注销应用程序(销毁所有会话数据)
6./用户重新登录twitter,twitter不应该重新授权,而应该识别用户并重定向到应用程序,该应用程序应该从twitter以某种方式进行身份验证,可能与数据库中的oauth令牌相匹配?
不确定这是否适用,但如果我在完成授权后立即登录twitter,它仍然要求我重新授权。
这是我的密码:
twitter登录代码
use Abraham\TwitterOAuth\TwitterOAuth;
$connection = new TwitterOAuth(twitter_apikey,twitter_apisecret);
$request_token= $connection->oauth('oauth/request_token', array('oauth_callback' => "https://example.com/twittercallback"));
$_SESSION['oauth_token']=$request_token['oauth_token'];
$_SESSION['oauth_token_secret']=$request_token['oauth_token_secret'];
$url = $connection->url("oauth/authorize", array("oauth_token" => $request_token['oauth_token']));
header('Location: '. $url);,这是我的回调代码:
use Abraham\TwitterOAuth\TwitterOAuth;
$oauth_access_token = $_SESSION['oauth_token'];
$oauth_access_token_secret = $_SESSION['oauth_verifier'];
$connection = new TwitterOAuth(twitter_apikey,twitter_apisecret,$oauth_access_token , $oauth_access_token_secret );
$access_token = $connection->oauth('oauth/access_token', array('oauth_verifier' => $_REQUEST['oauth_verifier'], 'oauth_token'=> $_GET['oauth_token']));
$connection = new TwitterOAuth(twitter_apikey,twitter_apisecret, $access_token['oauth_token'], $access_token['oauth_token_secret']);
$user_info = $connection->get('account/verify_credentials',['include_email'=>'true']);
$oauth_token = $access_token['oauth_token'];
$oauth_token_secret = $access_token['oauth_token_secret'];
print "<pre>".print_r($user_info,true)."</pre>";发布于 2019-05-16 04:41:34
您需要将用户重定向到https://api.twitter.com/oauth/authenticate而不是https://api.twitter.com/oauth/authorize。
https://developer.twitter.com/en/docs/basics/authentication/api-reference/authenticate.html
更改这一行
$url = $connection->url("oauth/authorize", array("oauth_token" => $request_token['oauth_token']));至
$url = $connection->url("oauth/authenticate", array("oauth_token" => $request_token['oauth_token']));https://stackoverflow.com/questions/56027641
复制相似问题