Skip to content

Instantly share code, notes, and snippets.

@joshuakfarrar
Created January 4, 2013 21:08
Show Gist options
  • Save joshuakfarrar/4456060 to your computer and use it in GitHub Desktop.
Save joshuakfarrar/4456060 to your computer and use it in GitHub Desktop.
app.get('/oauth', function(req, res) {
Instagram.oauth.ask_for_access_token({
request: req,
response: res,
redirect_uri: 'http://localhost:3000/oauth',
complete: function(params, oresponse) {
Instagram.users.search({ q: 'octocat', complete: function(users) {
var user = users[0];
Instagram.users.recent({ user_id: user.id, access_token: params.access_token, complete: function(media, pagination) {
function callApi(url) {
request.get({ url: url, json: true }, function(err, instaRes) {
Object.keys(instaRes.body.data).forEach(function(k) {
media.push(instaRes.body.data[k]);
});
if (instaRes.body.pagination.next_url) {
// oh noes recursion!
callApi(instaRes.body.pagination.next_url);
}
else {
// if we've got 'em all, write 'em out teh socket as html
res.writeHead(200, { 'content-type': 'text/html' });
Object.keys(media).forEach(function(k) {
res.write('<img src="'+ media[k].images.thumbnail.url +'">');
});
res.end();
}
});
}
callApi(pagination.next_url);
}});
}});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment