开发者

Retain Access Token in Epi Twitter Oauth

I'm setting up a website using the EPI Twitter Oauth method. I'm able to get a user to login and retrieve their information. However when I refresh the page that has their info, the info is lost. I'm guessing this is to do with the Access Token, and am hoping someone can suggest the easiest way to fix this.

<?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' =&g开发者_运维问答t; $msg));
 $temp = $update_status->response;

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

 }

?>


It looks to me that you are only checking $_GET for the oauth token. I believe that this may be causing this "lost info" issue because by the time you refresh the page the oauth token has been stored in a session variable and may no longer be stored in the URL. I think you may want to replace the following:

$oauth_token = $_GET['oauth_token'];

with

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜