Twitter OAuth问题
我正在尝试使用Twitter Oauth登录 index.phpTwitter OAuth问题,twitter,twitter-oauth,oauth-2.0,Twitter,Twitter Oauth,Oauth 2.0,我正在尝试使用Twitter Oauth登录 index.php <?php require ("twitteroauth/twitteroauth.php"); session_start(); // The TwitterOAuth instance $twitteroauth = new TwitterOAuth('00000000000000000', '0000000000000000000000000000000'); // Requesting authenticatio
<?php
require ("twitteroauth/twitteroauth.php");
session_start();
// The TwitterOAuth instance
$twitteroauth = new TwitterOAuth('00000000000000000', '0000000000000000000000000000000');
// Requesting authentication tokens, the parameter is the URL we will be redirected to
$request_token = $twitteroauth->getRequestToken('http://bakasura.in/twitter/twitter_oauth.php');
// Saving them into the session
$_SESSION['oauth_token'] = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
// If everything goes well..
if($twitteroauth->http_code==200){
// Let's generate the URL and redirect
$url = $twitteroauth->getAuthorizeURL($request_token['oauth_token']);
header('Location: '. $url);
} else {
// It's a bad idea to kill the script, but we've got to know when there's an error.
die('Something wrong happened.');
}
?>
页面加载后,当我单击“允许”时,它会将我带回授权页面
上面写着“未授权”
您可以在此处尝试您没有在第二页启动会话。只要不调用session_start(),会话变量就不可用
一些PHP设置已将其PHP.ini配置为自动启动会话,但当我查看您的服务器设置时,我发现您没有在第二页上发送PHP会话的cookie头,所以我很确定您的会话没有在第二页启动…看起来会话变量没有从index.php设置并传递。是的,这就是问题所在。谢谢只是确认一下——当我再次回到index.php时,它已经被授权了。再次要求我允许。我怎样才能做一次并在下次自动登录?我应该为特定用户存储OAuth组件的Wat凭据吗?
<?php
require ("twitteroauth/twitteroauth.php");
if(!empty($_GET['oauth_verifier']) && !empty($_SESSION['oauth_token']) && !empty($_SESSION['oauth_token_secret'])){
// We've got everything we need
echo "Authorized";
} else {
// Something's missing, go back to square 1
//header('Location: twitter_login.php');
echo "Not Authorized";
}
?>