Skip to content

Instantly share code, notes, and snippets.

@iksose
Forked from Dakuan/Simple Twitter Auth
Created June 23, 2014 17:16
Show Gist options
  • Save iksose/32225cacb3dba24c79e8 to your computer and use it in GitHub Desktop.
Save iksose/32225cacb3dba24c79e8 to your computer and use it in GitHub Desktop.
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