Skip to content

Instantly share code, notes, and snippets.

@joeyvandijk
Created January 15, 2016 15:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeyvandijk/7813c91e2dccdbb5c982 to your computer and use it in GitHub Desktop.
Save joeyvandijk/7813c91e2dccdbb5c982 to your computer and use it in GitHub Desktop.
// define libraries you would need
var oauth = require('oauth')
// define your OAuth-application credentials
var twitterConsumerKey = 'xxxxxxxxxxxxxxxxxxxx'
var twitterConsumerSecret = 'xxxxxxxxxxxxxxxxxxxx'
var api = new oauth.OAuth(
'https://twitter.com/oauth/request_token',
'https://twitter.com/oauth/access_token',
twitterConsumerKey,
twitterConsumerSecret,
'1.0A',
'',
'HMAC-SHA1'
)
// use the token information received after getting the access (!) token
var user = {
oauthToken: 'xxxxxxxxxxxxxxxxxxxx',
oauthSecret: 'xxxxxxxxxxxxxxxxxxxx'
}
// use starting point to only get new entries
var lastItem = '&since_id=12890371837123173' // id is of course dynamic and from a DB entry
api.get(
'https://api.twitter.com/1.1/statuses/home_timeline.json?count=20' + lastItem,
user.authToken,
user.authSecret,
function (error, items, response) {
if (error) {
console.log('Timeline error')
context.fail(JSON.stringify(error, null, 2))
} else {
var list = JSON.parse(items)
context.succeed({items:list})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment