From 3a3a8e97ee8b96d3aa90fe859ff1d5b250788c05 Mon Sep 17 00:00:00 2001 From: Sahat Yalkabov Date: Tue, 22 Apr 2014 14:51:35 -0400 Subject: [PATCH] Added Instagram API Example --- controllers/api.js | 54 ++++++++++++++++++++++++++++++++++++ views/api/index.jade | 5 ++++ views/api/instagram.jade | 60 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 views/api/instagram.jade diff --git a/controllers/api.js b/controllers/api.js index 2d276c9dbf..2e013f8c8f 100644 --- a/controllers/api.js +++ b/controllers/api.js @@ -16,6 +16,7 @@ var stripe = require('stripe')(secrets.stripe.apiKey); var twilio = require('twilio')(secrets.twilio.sid, secrets.twilio.token); var Linkedin = require('node-linkedin')(secrets.linkedin.clientID, secrets.linkedin.clientSecret, secrets.linkedin.callbackURL); var clockwork = require('clockwork')({key: secrets.clockwork.apiKey}); +var ig = require('instagram-node').instagram(); /** * GET /api @@ -500,3 +501,56 @@ exports.getLinkedin = function(req, res, next) { }); }); }; + +/** + * GET /api/instagram + * Instagram API example. + */ + +exports.getInstagram = function(req, res, next) { + var token = _.findWhere(req.user.tokens, { kind: 'instagram' }); + + ig.use({ access_token: token }); + ig.use({ client_id: secrets.instagram.clientID, client_secret: secrets.instagram.clientSecret }); + + async.parallel({ + searchByUsername: function(done) { + ig.user_search('lisa_veronica', function(err, users, limit) { + done(err, users); + }); + }, + searchByUserId: function(done) { + ig.user('175948269', function(err, user) { + console.log(user); + done(err, user); + }); + }, + popularImages: function(done) { + ig.media_popular(function(err, medias) { + done(err, medias); + }); + } + }, + function(err, results) { + res.render('api/instagram', { + title: 'Instagram API', + usernames: results.searchByUsername, + userById: results.searchByUserId, + popularImages: results.popularImages + }); + }); +}; + +exports.postInstagram = function(req, res, next) { + var token = _.findWhere(req.user.tokens, { kind: 'instagram' }); + + ig.use({ access_token: token }); + ig.use({ client_id: secrets.instagram.clientID, client_secret: secrets.instagram.clientSecret }); + + + + ig.user_search('13reasons', function(err, users, limit) { + console.log(users); + }); + +}; \ No newline at end of file diff --git a/views/api/index.jade b/views/api/index.jade index 88712134e2..83d210bf90 100644 --- a/views/api/index.jade +++ b/views/api/index.jade @@ -30,6 +30,11 @@ block content .panel-body img(src='https://github.global.ssl.fastly.net/images/modules/logos_page/Octocat.png', height=40) a(href='/api/github') GitHub + .col-sm-4 + .panel.panel-default + .panel-body + img(src='http://aweebitirish.com/wp-content/uploads/2014/03/instagram-app-icon-vector.png', height=40) + a(href='/api/instagram') Instagram .col-sm-4 .panel.panel-default .panel-body diff --git a/views/api/instagram.jade b/views/api/instagram.jade new file mode 100644 index 0000000000..4d5abb2baa --- /dev/null +++ b/views/api/instagram.jade @@ -0,0 +1,60 @@ +extends ../layout + +block content + .page-header + h2 + i.fa.fa-instagram + | Instagram API + .btn-group.btn-group-justified + a.btn.btn-primary(href='http://instagram.com/developer/', target='_blank') + i.fa.fa-check-square-o + | Overview + a.btn.btn-primary(href='https://github.com/teleportd/instagram-node', target='_blank') + i.fa.fa-laptop + | Node-Instagram Library + a.btn.btn-primary(href='http://instagram.com/developer/endpoints/', target='_blank') + i.fa.fa-code-fork + | API Endpoints + + br + p.lead Username Search for + strong lisa_veronica + table.table.table-hover.table-bordered + thead + tr + th Picture + th Username + th Full Name + th Bio + tbody + for user in usernames + tr + td + img(src='#{user.profile_picture}', width='75', height='75') + td= user.username + td= user.full_name + td= user.bio + + hr + p.lead User Search for ID + strong 175948269 + + + img.thumbnail(src='#{userById.profile_picture}', width='75', height='75') + p + a(href='http://instagram.com/#{userById.username}') + strong #{userById.full_name} + br + | #{userById.bio} + + hr + p.lead Popular Images on Instagram + .row + for image in popularImages + .col-xs-3 + a.thumbnail(href='#{image.link}') + img(src='#{image.images.standard_resolution.url}', height='320px') + div.facebook-caption + i.fa.fa-heart + | #{image.likes.count} +