Skip to content

Notice: Undefined index: oauth_token in C:\xampp\htdocs\twitterapi\callback.php on line 9 #2

@danish-manzoor

Description

@danish-manzoor

Notice: Undefined index: oauth_token in C:\xampp\htdocs\twitterapi\callback.php on line 5
Here is my all code
index.php
session_start();
require_once 'autoload.php';
use Abraham\TwitterOAuth\TwitterOAuth;
define('CONSUMER_KEY', 'Vn3Q6iF0N5CTelifVP7VP6cgq'); // add your app consumer key between single quotes
define('CONSUMER_SECRET', '5rt9AWrmJeV3UtGfU1cSS8G1tPg4GGNSYY6kSHsTMgvcMsTQDW'); // add your app consumer secret key between single quotes
define('OAUTH_CALLBACK', 'https://127.0.0.1/twitterapi/callback.php'); // your app callback URL
if (!isset($_SESSION['access_token'])) {
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
$request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => OAUTH_CALLBACK));
$_SESSION['oauth_token'] = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
$url = $connection->url('oauth/authenticate', array('oauth_token' => $request_token['oauth_token']));
echo $url;
echo 'Login to Twitter';
} else {
$access_token = $_SESSION['access_token'];
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
$user = $connection->get("account/verify_credentials");
echo $user->screen_name;
}
callback.php

session_start();
require 'autoload.php';
use Abraham\TwitterOAuth\TwitterOAuth;
if(isset($_REQUEST['oauth_verifier'],$_REQUEST['oauth_token']) && $_REQUEST['oauth_token']=== $_SESSION['oauth_token']){
$request_token = [];
$request_token['oauth_token'] = $_SESSION['oauth_token'];
$request_token['oauth_token_secret'] = $_SESSION['oauth_token_secret'];
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $request_token['oauth_token'], $request_token['oauth_token_secret']);
$access_token = $connection->oauth("oauth/access_token", array("oauth_verifier" => $_REQUEST['oauth_verifier']));
$_SESSION['access_token'] = $access_token;
// redirect user back to index page
header('Location: ./');
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions