Skip to content

Instantly share code, notes, and snippets.

Created February 4, 2014 19:17
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 anonymous/8810353 to your computer and use it in GitHub Desktop.
Save anonymous/8810353 to your computer and use it in GitHub Desktop.
Instagram API code
(function () {
"use strict";
var insta = window.insta = window.insta || {}; // insta Object
insta = {
feedUrl: 'https://api.instagram.com/v1/users/self/feed?access_token=[token here]&callback=?',
grams: {},
init: function () {
$.ajax({
type: 'GET',
url: insta.apiUrl,
dataType: 'json',
success: insta.success
});
},
renderGrams: function (grams) {
$.each(grams, function(index, gram) {
insta.grams[gram.id] = gram;
var gramHtml = '<div class="col-md-3"><p><img class="img-circle" style="margin-right: 5px" width="60" src="' + gram.user.profile_picture + '">' + gram.user.username + '</p><a href="#myModal" data-toggle="modal" data-media-id="' + gram.id +'">';
if (gram.type === 'image') { gramHtml = gramHtml + '<img class="img-thumbnail" src="' + gram.images.low_resolution.url + '"/>'; }
if (gram.type === 'video') { gramHtml = gramHtml + '<video class="img-thumbnail" src="' + gram.videos.low_resolution.url + '"/>'; }
gramHtml = gramHtml + '</a></div>';
$('.results').append(gramHtml);
});
},
setupClickEvent: function () {
$('a').click(function(){
var mediaId = $(this).data('mediaId'),
gram = insta.grams[mediaId],
largeImage = gram.images.standard_resolution.url,
username = gram.user.username,
tags = gram.tags,
comments = '';
$('.modal-title').html(username);
$('.modal-body').html('<div class="col-md-6"><img class="img-responsive" src="' + largeImage + '"><div class="tagwrap">' + tags + '</div></div>');
$.each(gram.comments.data, function(index, comment){
comments += '<p>' + comments.text + '</p>';
});
$('.comments-container').html(comments);
});
},
success: function (responseData) {
if (responseData.meta.code === 200) {
insta.renderGrams(responseData.data);
insta.setupClickEvent();
} else {
$('.results').html('<h1>An Error Occured</h1><p>' + responseData.meta.error_message + '</p>');
}
}
};
// This actually fires fires everything off
// Follow from here
insta.init();
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment