Created
May 4, 2011 13:30
-
-
Save e2kaneko/955209 to your computer and use it in GitHub Desktop.
PHP - TwitterOAuthLogin~Callback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ----- Authorization ----- // | |
$consumerKey = TWITTER_CONSUMER_KEY; | |
$consumerSecret = TWITTER_CONSUMER_SECRET; | |
$callbackUrl = "http://example.com/action/TwitterAuthCallback"; | |
$oAuth = new HTTP_OAuth_Consumer($consumerKey, $consumerSecret); | |
$httpRequest = new HTTP_Request2(); | |
$httpRequest->setConfig("ssl_verify_peer", false); | |
$consumerRequest = new HTTP_OAuth_Consumer_Request; | |
$consumerRequest->accept($httpRequest); | |
$oAuth->accept($consumerRequest); | |
$oAuth->getRequestToken("https://twitter.com/oauth/request_token", $callbackUrl); | |
$_SESSION["oauth_request_token"] = $oAuth->getToken(); | |
$_SESSION["oauth_request_token_secret"] = $oAuth->getTokenSecret(); | |
$authorizeUrl = $oAuth->getAuthorizeURL("https://twitter.com/oauth/authorize"); | |
header("Location: " . $authorizeUrl); | |
?> | |
<?php | |
// ----- callback ----- // | |
$consumerKey = CONSUMER_KEY; | |
$consumerSecret = CONSUMER_SECRET; | |
$oAuth = new HTTP_OAuth_Consumer($consumerKey, $consumerSecret); | |
$httpRequest = new HTTP_Request2(); | |
$httpRequest->setConfig("ssl_verify_peer", false); | |
$consumerRequest = new HTTP_OAuth_Consumer_Request; | |
$consumerRequest->accept($httpRequest); | |
$oAuth->accept($consumerRequest); | |
$oAuthToken = $_GET{"oauth_token"}; | |
$oAuth->setToken($oAuthToken); | |
$oAuth->setTokenSecret($_SESSION["oauth_request_token_secret"]); | |
$oAuthVerifier = $_REQUEST["oauth_verifier"]; | |
$_SESSION["oauth_request_token"] = null; | |
$_SESSION["oauth_request_token_secret"] = null; | |
$oAuth->getAccessToken("https://twitter.com/oauth/access_token", $oAuthVerifier); | |
$accessToken = $oAuth->getToken(); | |
$accessTokenSecret = $oAuth->getTokenSecret(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment