Php Twitter API出现无效/过期的令牌错误

Php Twitter API出现无效/过期的令牌错误,php,twitter,twitter-oauth,Php,Twitter,Twitter Oauth,我正在使用Jason Mathai的PHP OAUTH库,每当我尝试使用以下测试代码访问用户信息时,我总是会收到一个无效/过期的令牌错误: //sessions stuff here session_start(); //twitter stuff include 'lib/EpiCurl.php'; include 'lib/EpiOAuth.php'; include 'lib/EpiTwitter.php'; include 'lib/secret.php'; //ensu

我正在使用Jason Mathai的PHP OAUTH库,每当我尝试使用以下测试代码访问用户信息时,我总是会收到一个无效/过期的令牌错误:

//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();  
                      }   

所有的方法都直接映射到使用twitterapi的httpget调用。我假设我的问题与Jason的库无关(因为它使用得相当好),而是与我的逻辑有关。感谢您的帮助

一旦您从twitter获得oauth_令牌,您就将其存储到会话中,并且每次您使用同一存储会话发出请求时都会将其存储到会话中。令牌在服务器上设置了一些到期时间,所以在一段时间后,您开始得到到期令牌错误


可以让您了解如何创建一个简单的twitter应用程序。

一旦您从twitter获得oauth_令牌,您就可以将其存储到会话中,并且每次您使用相同的存储会话发出请求时都会将其存储到会话中。令牌在服务器上设置了一些到期时间,所以在一段时间后,您开始得到到期令牌错误


可以让您了解如何创建一个简单的twitter应用程序。

这是他使用的链接,但是“链接上的代码”和“发布的代码”在不同的位置使用会话。这是他使用的链接,但是“链接上的代码”和“发布的代码”在不同的位置使用会话。