我有一个用户系统,我将用户ID存储在$_SESSION['uid']
中,用户可以浏览他的帐户设置,但我最近添加了链接您的Twitter帐户的功能...这是它获得的地方奇
我有一个像这样的推特请求页面:
session_start();
require("twitteroauth/twitteroauth.php");
// The TwitterOAuth instance
$twitteroauth = new TwitterOAuth('***', '***');
// Requesting authentication tokens, the parameter is the URL we will be redirected to
$request_token = $twitteroauth->getRequestToken('http://livepierced.com/reg_twit.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']);
//var_dump($url);
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.');
}
此时我可以转储会话,并获取UID
,AuthToken
和AuthTokenSecret
然而,一旦我点击了twitters方面的授权,我就会被发回到这个页面:
session_start();
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 "<h1>TOKEN GOOD BRO!</h1>";
} else {
// Something's missing, go back to square 1
//var_dump($_REQUEST);
//header('Location: req_twit.php');
}
但是,现在我的会话已被销毁,或已启动新会话,因为var转储$ _SESSION只会给我一个会话ID
答案 0 :(得分:0)
当标题重定向发生时,它是否会更改为不同的网址或子网域?例如,您是从mywebsite.com开始并最终访问www.mywebsite.com吗?
我从未使用过twitter api,但这是我的第一个想法。