I have create a request with https://github.com/abraham/twitteroauth, I create two file
first twitter-login.php
<?php
require("twitteroauth/twitteroauth.php");
session_start();
// 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('http://belajar.yusyaif.com/twitteroauth-master/twitter-oauth.php');
// 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..
if($twitteroauth->http_code==200){
// 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.');
}
?>
and
twitter-update.php
<?php
require("twitteroauth/twitteroauth.php");
session_start();
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
print_r($user_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 https://api.twitter.com/oauth/authenticate
last word I’m sorry for my bad English, home you know my problem and help me to fix it 