在Epi Twitter Oauth中保留访问令牌

时间:2010-11-09 15:57:58

标签: twitter twitter-oauth

我正在使用EPI Twitter Oauth方法建立一个网站。我能够让用户登录并检索他们的信息。但是,当我刷新包含其信息的页面时,信息将丢失。我猜这与访问令牌有关,我希望有人能提出最简单的解决方法。

<?php 

include 'lib/EpiCurl.php';
include 'lib/EpiOAuth.php';
include 'lib/EpiTwitter.php';
include 'lib/secret.php';

$twitterObj = new EpiTwitter($consumer_key, $consumer_secret);
$oauth_token = $_GET['oauth_token'];
 if($oauth_token == '')
 {
 $url = $twitterObj->getAuthorizationUrl();
 echo "<div id=\"container\">";
  echo "<div id=\"content\">";
   echo "<div id=\"holder\">";
   echo "</div>";
   echo "<div id=\"nav\">";
    echo "<a href='$url'><img src=\"signup.jpg\" class=\"linkimage\" /></a>";
   echo "</div>";
  echo "</div>";
 echo "</div>";
}
 else
 {
 $twitterObj->setToken($_GET['oauth_token']);
 $token = $twitterObj->getAccessToken();
 $twitterObj->setToken($token->oauth_token, $token->oauth_token_secret);
 $_SESSION['ot'] = $token->oauth_token;
 $_SESSION['ots'] = $token->oauth_token_secret;
 $twitterInfo= $twitterObj->get_accountVerify_credentials();
 $twitterInfo->response;



 $username = $twitterInfo->screen_name;
 $profilepic = $twitterInfo->profile_image_url;

 include 'home.php';

 }

if(isset($_POST['submit']))
 {
 $msg = $_REQUEST['tweet'];

 $twitterObj->setToken($_SESSION['ot'], $_SESSION['ots']);
 $update_status = $twitterObj->post_statusesUpdate(array('status' => $msg));
 $temp = $update_status->response;

 echo "<br /><div align='center'>Updated your Timeline Successfully .</div>";

 }

?>

1 个答案:

答案 0 :(得分:0)

在我看来,您只是在检查$_GET oauth令牌。我相信这可能会导致这个“丢失信息”问题,因为当您刷新页面时,oauth令牌已存储在会话变量中,并且可能不再存储在URL中。我想你可能想要替换以下内容:

$oauth_token = $_GET['oauth_token'];

$oauth_token = empty($_SESSION['ot']) ? $_SESSION['ot'] : $_GET['oauth_token'];