Code Monkey home page Code Monkey logo

twitter-api-php's Introduction

twitter-api-php's People

Contributors

sohaibilyas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

twitter-api-php's Issues

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

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: ./');
}

Undefined index: oauth_token

hi
I'm having a problem with the code, I did copy the src and autorun files and also I did copy the index and callback code from your gist, it opens the the twitter authorization page and when I click authorize
it gives me the error Undefined index: oauth_token in callback.php on line 6

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.