我正在使用 Abraham William 的 Twitter oAuth 库。
以下是我的代码:
if (isset($_REQUEST['oauth_token'])){
print_r($_SESSION);
exit;
}
/* Build TwitterOAuth object with client credentials. */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
/* Get temporary credentials. */
$request_token = $connection->getRequestToken(OAUTH_CALLBACK);
/* Save temporary credentials to session. */
$_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
/* If last connection failed don't display authorization link. */
switch ($connection->http_code) {
case 200:
/* Build authorize URL and redirect user to Twitter. */
$url = $connection->getAuthorizeURL($token);
print "<script>self.location='$url';</script>";
break;
default:
/* Show notification if something went wrong. */
echo 'Could not connect to Twitter. Refresh the page or try again later.';
return;
}
如果我在重定向之前检查 $_SESSION,$_SESSION 就在那里。发生重定向时,设置了 $_REQUEST['oauth_token'] (我验证了这一点),但 $_SESSION 不再存在。
我的浏览器设置为接受 cookie 和第三方 cookie。有任何想法吗?