Created
January 15, 2016 15:17
-
-
Save joeyvandijk/7813c91e2dccdbb5c982 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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