编辑我有这个问题与chrome我测试了我的脚本 firefox及其正常工作
我正在使用twitterOAuth
api为我的网站进行Twitter身份验证,但是当我授权我的Twitter应用程序返回我的回调网址时,它无法验证oauth_token
,因为$ _SESSION ['oauth_token' ]值已更改
这是我的代码index.php,它生成用于身份验证的URL和存储会话变量
<?php
require 'autoload.php';
use Abraham\TwitterOAuth\TwitterOAuth;
define('CONSUMER_KEY', 'abc');
define('CONSUMER_SECRET', 'abc');
define('OAUTH_CALLBACK', 'http://example.tk/callback.php');
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
$request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => OAUTH_CALLBACK));
session_start();
$_SESSION['oauth_token'] = $request_token['oauth_token'];
echo "From Sessoin ".$_SESSION['oauth_token']."<br>";
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
$url = $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token']));
echo '<a href="'.$url.'">Login with twitter</a>';
?>
这是回调网址的代码。此处用户在授权应用进行身份验证后会重定向
<?php
session_start();
require 'autoload.php';
use Abraham\TwitterOAuth\TwitterOAuth;
define('CONSUMER_KEY', 'NxEvR3DcegC83BEKWsSqPrBpG');
define('CONSUMER_SECRET', 'hRPggFw6WNYcl8MfdOGb177y3JVwbAoSZEd2tR1HlJXq5jSRmL');
define('OAUTH_CALLBACK', 'http://www.skywebdeveloper.tk/callback.php');
$request_token = [];
$request_token['oauth_token'] = $_SESSION['oauth_token'];
$request_token['oauth_token_secret'] = $_SESSION['oauth_token_secret'];
if (isset($_REQUEST['oauth_token']) && $request_token['oauth_token'] !== $_REQUEST['oauth_token']) {
// Abort! Something is wrong.
echo "From Sessoin ".$_SESSION['oauth_token'];
echo "<br>From Request Method ".$_REQUEST['oauth_token'];
}
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $request_token['oauth_token'], $request_token['oauth_token_secret']);
//$access_token = $connection->oauth("oauth/access_token", array("oauth_verifier" => $_REQUEST['oauth_verifier']));
//echo $access_token;
?>
我评论了$access_token
调试$_SESSION
变量,该变量随时间变化。 $ access_token返回错误无效令牌,这是因为它无法验证带有数据发回的会话变量