1
我使用賈森馬的PHP OAUTH庫令牌錯誤,我不斷收到一個無效/到期令牌錯誤,每當我嘗試用下面的測試代碼訪問用戶的信息:無效/過期與Twitter API
//sessions stuff here
session_start();
//twitter stuff
include 'lib/EpiCurl.php';
include 'lib/EpiOAuth.php';
include 'lib/EpiTwitter.php';
include 'lib/secret.php';
//ensure token is set for the session
$twitterObj = new EpiTwitter($consumer_key, $consumer_secret);
if($_GET['oauth_token']){
$_SESSION['o_token'] = $_GET['oauth_token'];
}
if(!isset($_SESSION['o_token']))
{
$url = $twitterObj->getAuthorizationUrl();
header("Location:$url");
die();
}
$o_token = $_SESSION['o_token'];
$twitterObj->setToken($o_token);
$token = $twitterObj->getAccessToken();
$twitterObj->setToken($token->oauth_token, $token->oauth_token_secret);
setcookie('oauth_token', $token->oauth_token);
setcookie('oauth_token_secret', $token->oauth_token_secret);
$twitterObj = new EpiTwitter($consumer_key, $consumer_secret,$_COOKIE['oauth_token'], $_COOKIE['oauth_token_secret']);
$twitterInfo= $twitterObj->get_accountVerify_credentials();
$twitterInfo->response;
var_dump($twitterInfo->response); // this tells me the error
try{
echo $twitterInfo->screen_name;
}catch(EpiTwitterException $e){
echo $e->getMessage();
}
所有的方法直接映射到HTTP與twitter API的調用我認爲我的問題與Jason的庫無關(因爲它的使用相當好),但與我的邏輯有關。所有幫助表示讚賞!
這是他使用的鏈接 – tekknolagi
我認爲。至少從代碼。 – tekknolagi
雅,但鏈接和發佈代碼上的代碼正在不同的地方使用會話。 –