Skip to content

@tjlytle /oauth.php
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Command Line Script to get Access Token using Zend_Twitter
#!/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
Something went wrong with that request. Please try again.