getRequestToken();
/* Save tokens for later */
$_SESSION['oauth_request_token'] = $token = $tok['oauth_token'];
$_SESSION['oauth_request_token_secret'] = $tok['oauth_token_secret'];
$_SESSION['oauth_state'] = "start";
/* Build the authorization URL */
$request_link = $to->getAuthorizeURL($token);
/* Build link that gets user to twitter to authorize the app */
$content = 'Click on the link to go to twitter to authorize your account.';
$content .= '
'.$request_link.'';
break;
case 'returned':
/* If the access tokens are already set skip to the API call */
if ($_SESSION['oauth_access_token'] === NULL && $_SESSION['oauth_access_token_secret'] === NULL) {
/* Create TwitterOAuth object with app key/secret and token key/secret from default phase */
$to = new TwitterOAuth($consumer_key, $consumer_secret, $_SESSION['oauth_request_token'], $_SESSION['oauth_request_token_secret']);
/* Request access tokens from twitter */
$tok = $to->getAccessToken();
/* Save the access tokens. Normally these would be saved in a database for future use. */
$_SESSION['oauth_access_token'] = $tok['oauth_token'];
$_SESSION['oauth_access_token_secret'] = $tok['oauth_token_secret'];
}
/* Random copy */
$content = 'your account should now be registered with twitter. Check here:
';
$content .= 'https://twitter.com/account/connections';
/* Create TwitterOAuth with app key/secret and user access key/secret */
$to = new TwitterOAuth($consumer_key, $consumer_secret, $_SESSION['oauth_access_token'], $_SESSION['oauth_access_token_secret']);
/* Run request on twitter API as user. */
$content = $to->OAuthRequest('https://twitter.com/account/verify_credentials.xml', array(), 'GET');
//$content = $to->OAuthRequest('https://twitter.com/statuses/update.xml', array('status' => 'Test OAuth update.'), 'POST');
//$content = $to->OAuthRequest('https://twitter.com/statuses/replies.xml', array(), 'POST');
break;
}/*}}}*/
?>
This site is a basic showcase of Twitters new OAuth authentication method. Everything is saved in sessions. If you want to start over clear sessions.
Consumer Key:
Consumer Secret:
Access Token:
Access Token Secret:
Get the code powering this at http://github.com/abraham/twitteroauth
Read the documentation at https://docs.google.com/View?docID=dcf2dzzs_2339fzbfsf4