Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Command Line Script to get Access Token using Zend_Twitter
//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' => '',
'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));
//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;
//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