Alright, I am still trying to solve this problem. Below is my code. Iâm using Abrahamâs oauth library.
require(âtwitteroauth/twitteroauth.phpâ);
unset($_SESSION[âtestâ]);
session_destroy();
session_unset();
session_start();
// The TwitterOAuth instance
$twitteroauth = new TwitterOAuth(âconsumerâ, âconsumerâ);
// Requesting authentication tokens, the parameter is the URL we will be redirected to
$request_token = $twitteroauth->getRequestToken(âhttp://exhilaraterockford.com/twitter_oauthâ);
// 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.â);
}
Above is the login script, which then redirects the user to Twitter. They login and are sent back to /twitter_oauth, which has this code:
<?php
require(âlogin.phpâ);
require(âtwitteroauth/twitteroauth.phpâ);
session_start();
mysql_select_db($db_database);
if(!empty($_SESSION[âusernameâ])){
// User is logged in, redirect
header(âLocation: /appreciateâ);
}
if(!empty($_GET[âoauth_verifierâ]) && !empty($_SESSION[âoauth_tokenâ]) && !empty($_SESSION[âoauth_token_secretâ])){
// Weâve got everything we need
} else {
// Somethingâs missing, go back to square 1
header(âLocation: /twitter_loginâ);
}
// TwitterOAuth instance, with two new parameters we got in twitter_login.php
$twitteroauth = new TwitterOAuth(âConsumerâ, âConsumerâ, $_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(âaccount/verify_credentials.jsonâ);
?>
I am seeing a few things. The session is updating and getting a new signature and nonce. The token and verifier remain the same. When I run $user_info = $twitteroauth->get(âaccount/verify_credentials.jsonâ); I receive the following: âstdClass Object ( [errors] => Array ( [0] => stdClass Object ( [message] => Bad Authentication data [code] => 215 ) ) )â
Any help would be appreciated.