Skip to content

Instantly share code, notes, and snippets.

@gkossakowski
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gkossakowski/c2d573a74f5a693c4160 to your computer and use it in GitHub Desktop.
Save gkossakowski/c2d573a74f5a693c4160 to your computer and use it in GitHub Desktop.
Asynchronous fetching of tweets from Twitter
function fetchTweets(username, callback) {
jQuery.ajax({
url: "http://api.twitter.com/1/
statuses/user_timeline.json/",
type: "GET",
dataType: "jsonp",
data: {
screen_name : username,
include_rts : true,
count : 5,
include_entities : true
},
success: callback
})
}
var processed = 0
var users = ["gkossakowski", "odersky", "adriaanm"]
users.forEach(function (user) {
console.log("fetching " + user)
fetchTweets(user, function(data) {
console.log("finished fetching " + user)
data.forEach(function (tweet) {
console.log("fetched " + tweet.text)
})
processed += 1
if (processed == users.length) {
console.log("done")
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment