Invalid / expired token


I have create a request with, I create two file
first twitter-login.php


// The TwitterOAuth instance
$twitteroauth = new TwitterOAuth('XXX', 'XXX');
// Requesting authentication tokens, the parameter is the URL we will be redirected to
$request_token = $twitteroauth->getRequestToken('');
// Saving them into the session
$_SESSION['oauth_token'] = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
// If everything goes well..
    // Let's generate the URL and redirect
    $url = $twitteroauth->getAuthorizeURL($request_token['oauth_token']);
    header('Location: '. $url);
} else {
    // It's a bad idea to kill the script, but we've got to know when there's an error.
    die('Something wrong happened.');




if(!empty($_GET['oauth_verifier']) && !empty($_SESSION['oauth_token']) && !empty($_SESSION['oauth_token_secret'])){  
        // TwitterOAuth instance, with two new parameters we got in twitter_login.php  
    $twitteroauth = new TwitterOAuth('XXX', 'XXX', $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);  
    // Let's request the access token  
    $access_token = $twitteroauth->getAccessToken($_GET['oauth_verifier']); 
    // Save it in a session var 
    $_SESSION['access_token'] = $access_token; 
    // Let's get the user's info 
    $user_info = $twitteroauth->get('statuses/home_timeline'); 
    // Print user's info  
} else {  
    // Something's missing, go back to square 1  
    header('Location: twitter-login.php');  

I have set consumer key and consumer secret key.
When I run that code for the first time, it run normally, I’m not got an error and it success.
But when I refresh the page I get this error

Notice: Undefined index: oauth_token in E:\xampp\htdocs\twitteroauth-master\twitteroauth\twitteroauth.php on line 118

Notice: Undefined index: oauth_token_secret in E:\xampp\htdocs\twitteroauth-master\twitteroauth\twitteroauth.php on line 118

I have googling but I got nothing! I know the problem is I never stored my oauth_token and oauth_token_secret and oauth_verifier
I don’t know how to store it, so please tell me how to store it and use it again when I need it. I mean, I want when I reload or refresh the page user mustn’t verified their credential on

last word I’m sorry for my bad English, home you know my problem and help me to fix it :slight_smile:


Running getAuthorizeURL and getAccessToken you only want to run once. After you have run those once you want get('statuses/home_timeline') to run only if you have an access_token set.


how can i use access_token, this access_token i have get it,
I read your code i can’t find where it is used?


oK I konw

I read your I konw vwery thing


twitter api 1. is good …please start it again…