Using twitterOAuth for login scripts


#1

I recently started working with twitteroauth login, which seems to be working in the examples but not when I amalgamate the redirect.php and callback.php
Based on the script below (which is integrated in a bit of log in script I’ve been working on) the second portion works fine (which is based on redirect.php), returning and oauth_token and oauth_verifier, but the first part (based on callback.php) isn’t even initiating it seems.

Any ideas/suggestions folks?

session_start();
require_once('socialCodes.php');    //where I keep my app ID and Secret
require_once('twitteroauth/twitteroauth.php');

if (isset($_GET['oauth_token'])) {	// we're being called back by Twitter
	$connection = new TwitterOAuth($twAppID, $twAppSec, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
	$connection->host = "https://api.twitter.com/1.1/";

	$access_token = $connection->getAccessToken($_GET['oauth_verifier']);

	$_SESSION['access_token'] = $access_token;

	unset($_SESSION['oauth_token']);
	unset($_SESSION['oauth_token_secret']);

	if (200 == $connection->http_code) {
		$userAccessToken = $access_token['oauth_token'];
		$userSecretToken = $access_token['oauth_token_secret'];
		$userID = $access_token['user_id'];
		$userName = $access_token['screen_name'];
	}

} else {
	$connection = new TwitterOAuth($twAppID, $twAppSec);
	$connection->host = "https://api.twitter.com/1.1/";
 
	$request_token = $connection->getRequestToken('myhomepage');

	$_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
	$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
 
	switch ($connection->http_code) {
	  case 200:
	    $url = $connection->getAuthorizeURL($token);
	    header('Location: ' . $url); 
    	break;
	  default:
	  echo 'Could not connect to Twitter. Refresh the page or try again later.';
	}
}

#2

How do you know the first part doesn’t work? From the code here it looks like it should get an access_token, set some variables, and then do nothing.


#3

My apologies, I forgot to close this discussion when I closed my StackOverflow discussion.
Turns out it was a caching issue, it worked the next day.