-
-
Save iksose/32225cacb3dba24c79e8 to your computer and use it in GitHub Desktop.
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
var OAuth2 = require('OAuth').OAuth2; | |
var https = require('https'); | |
var oauth2 = new OAuth2(KEY, SECRET, 'https://api.twitter.com/', null, 'oauth2/token', null); | |
oauth2.getOAuthAccessToken('', { | |
'grant_type': 'client_credentials' | |
}, function (e, access_token) { | |
console.log(access_token); //string that we can use to authenticate request | |
var options = { | |
hostname: 'api.twitter.com', | |
path: '/1.1/statuses/user_timeline.json?screen_name=mostlyharmlessd', | |
headers: { | |
Authorization: 'Bearer ' + access_token | |
} | |
}; | |
https.get(options, function (result) { | |
var buffer = ''; | |
result.setEncoding('utf8'); | |
result.on('data', function (data) { | |
buffer += data; | |
}); | |
result.on('end', function () { | |
var tweets = JSON.parse(buffer); | |
console.log(tweets); // the tweets! | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment