Skip to content

Instantly share code, notes, and snippets.

@csrui
Created January 14, 2014 10:42
Show Gist options
  • Save csrui/8416438 to your computer and use it in GitHub Desktop.
Save csrui/8416438 to your computer and use it in GitHub Desktop.
OAuth requests with library Unirest.io
var Request = unirest.get('https://api.twitter.com/oauth/request_token');
Request.oauth({
callback: 'http://mysite.com/callback/'
, consumer_key: 'CONSUMER_KEY'
, consumer_secret: 'CONSUMER_SECRET'
}).end(function (response) {
var access_token = response.body;
Request = unirest.post('https://api.twitter.com/oauth/access_token');
Request.oauth({
consumer_key: 'CONSUMER_KEY'
, consumer_secret: 'CONSUMER_SECRET'
, token: access_token.oauth_token
, verifier: token: access_token.oauth_verifier
}).end(function (response) {
var token = response.body;
Request = unirest.get('https://api.twitter.com/1/users/show.json');
Request.oauth({
consumer_key: 'CONSUMER_KEY'
, consumer_secret: 'CONSUMER_SECRET'
, token: token.oauth_token
, token_secret: token.oauth_token_secret
}).query({
screen_name: token.screen_name
, user_id: token.user_id
}).end(function (response) {
console.log(response.body);
});
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment