Question

I am trying to use Twitter Oauth to login.

index.php

<?php
require ("twitteroauth/twitteroauth.php");
session_start();

// The TwitterOAuth instance
$twitteroauth = new TwitterOAuth('00000000000000000', '0000000000000000000000000000000');

// Requesting authentication tokens, the parameter is the URL we will be redirected to
$request_token = $twitteroauth->getRequestToken('http://bakasura.in/twitter/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.');
}

?>

Once the page loads it takes me to the Authorization Page When i click Allow it takes me back to the http://bakasura.in/twitter/twitter_oauth.php

<?php
require ("twitteroauth/twitteroauth.php");

if(!empty($_GET['oauth_verifier']) && !empty($_SESSION['oauth_token']) && !empty($_SESSION['oauth_token_secret'])){

    // We've got everything we need
    echo "Authorized";

} else {

    // Something's missing, go back to square 1
    //header('Location: twitter_login.php');
    echo "Not Authorized";

}
?> 

And it says "Not Authorized"

you can try it here http://bakasura.in/twitter/

Was it helpful?

Solution

you did not start your session in the second page. As long as you do not call session_start(), your session variables are not available

Some PHP setups have configured their php.ini to autostart your session, but when I look at your server setup, I see you are not sending out a cookie header for your php session on your second page, so I'm pretty sure that your session is not started on your second page...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top