Forked from tanepiper/twitter_oauth_getter.js
Created
October 25, 2010 10:01
Star
You must be signed in to star a gist
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/env node | |
var argv = require('optimist').argv; | |
var sys = require('sys'); | |
var OAuth = require('oauth').OAuth; | |
function getAccessToken(oa, oauth_token, oauth_token_secret, pin) { | |
oa.getOAuthAccessToken(oauth_token, oauth_token_secret, pin, | |
function(error, oauth_access_token, oauth_access_token_secret, results2) { | |
if (error) { | |
console.log(error); | |
return; | |
} | |
sys.puts('Your OAuth Access Token:' + oauth_access_token); | |
sys.puts('Your OAuth Token Secret: ' + oauth_access_token_secret); | |
sys.puts('Now, save these two values, along with your origional consumer secret and key and use these in your twitter app'); | |
process.exit(1); | |
}); | |
} | |
function getRequestToken(oa) { | |
oa.getOAuthRequestToken(function(error, oauth_token, oauth_token_secret, results){ | |
if(error) { | |
sys.puts('error :' + error); | |
} else { | |
sys.puts('In your browser, log in to your twitter account. Then visit:') | |
sys.puts('https://twitter.com/oauth/authorize?oauth_token=' + oauth_token) | |
sys.puts('After logged in, you will be promoted with a pin number') | |
sys.puts('Enter the pin number here:'); | |
var stdin = process.openStdin(); | |
stdin.on('data', function(chunk) { | |
pin = chunk.toString().trim(); | |
getAccessToken(oa, oauth_token, oauth_token_secret, pin); | |
}); | |
} | |
}); | |
} | |
function startAuth() { | |
if(argv.help) { | |
console.log("You've got the --key= You've got the --secret="); | |
return | |
} | |
if (!argv.key) { | |
sys.puts('You must pass a --key= parameter'); | |
return; | |
} | |
if (!argv.secret) { | |
sys.puts('You must pass a --secret= parameter'); | |
return | |
} | |
var oa = new OAuth('http://api.twitter.com/oauth/request_token', | |
'http://api.twitter.com/oauth/access_token', | |
argv.key.trim(), | |
argv.secret.trim(), | |
'1.0', | |
null, 'HMAC-SHA1'); | |
getRequestToken(oa); | |
} | |
startAuth(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment