Tuesday, 6 August 2013

Twitter Login: Redirect is not working

Twitter Login: Redirect is not working

I am trying to implement Login With twitter api using Twitter oauth PHP
library. Everything seems to be work fine. I get the Twitter Sign In
screen for the user. As per the code I get $twitteroauth->http_code as
200. But it keep redirecting page to the same Twitter Login screen. Here
is my code:
function loginTwitter()
{
// The TwitterOAuth instance
$twitteroauth = new TwitterOAuth('xxx', 'xxxxx');
// Requesting authentication tokens, the parameter is the URL we
will be redirected to
$request_token =
$twitteroauth->getRequestToken('http://localhost/testsaav/socialAuth/twitterAuth');
// 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.');
}
}

No comments:

Post a Comment