Created
June 8, 2011 16:32
-
-
Save tjlytle/1014769 to your computer and use it in GitHub Desktop.
Command Line Script to get Access Token using Zend_Twitter
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
#!/usr/bin/php | |
<?php | |
//consumer key and secret | |
$key = "APPKEY"; | |
$secret = "APPSECRET"; | |
require_once 'Zend/Oauth/Consumer.php'; | |
//setup consumer like any other request, note that the 'oob' callbackUrl cannot | |
//be set at this point (will throw an exception) | |
$consumer = new Zend_Oauth_Consumer(array( | |
'siteUrl' => 'https://twitter.com/oauth', | |
'consumerKey' => $key, | |
'consumerSecret' => $secret | |
)); | |
//get the request token, using the speciall 'oob' callbackUrl | |
$requestToken = $consumer->getRequestToken(array('callbackUrl' => 'oob')); | |
//output the link, and request the pin | |
echo "OAuth Link: {$consumer->getRedirectUrl()}" . PHP_EOL; | |
fwrite(STDOUT, "Enter the PIN: "); | |
//get the pin and use it to get an access token | |
$pin = trim(fgets(STDIN)); | |
try{ | |
//acting like a normal $_GET array, use the pin as the verifier, and add the | |
//token (since a normal oauth process would have passed the original token) | |
$accessToken = $consumer->getAccessToken(array('oauth_verifier' => $pin, 'oauth_token' => $requestToken->getToken()), $requestToken); | |
} catch (Zend_Oauth_Exception $e){ | |
echo $e->getMessage() . PHP_EOL; | |
exit; | |
} | |
//output the access token and secret | |
echo "OAuth Token: {$accessToken->getToken()}" . PHP_EOL; | |
echo "OAuth Secret: {$accessToken->getTokenSecret()}" . PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment