Skip to content

Instantly share code, notes, and snippets.

@tomblanchard
Created December 6, 2014 21:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomblanchard/33def2cdc6a67e75914f to your computer and use it in GitHub Desktop.
Save tomblanchard/33def2cdc6a67e75914f to your computer and use it in GitHub Desktop.
Instagram feed.
<ul class="instagram__items"></ul>
(function() {
var settings = {
userId: '0000000000', // http://jelled.com/instagram/lookup-user-id
accessToken: '123456789.1abc12a.a1234ab123456789a123456abcd1a1ab', // http://jelled.com/instagram/access-token
numPosts: 5,
postsEl: '.instagram__items'
}
$.ajax({
url: 'https://api.instagram.com/v1/users/' + settings.userId + '/media/recent/?access_token=' + settings.accessToken + '&count=' + settings.numPosts,
dataType: 'jsonp',
cache: true,
success: appendPosts
});
function appendPosts( data ) {
var html = '';
for ( var i = 0, len = data.data.length; i < len ; i++ ) {
var post = data.data[i],
postLink = post.link,
postImage = post.images.low_resolution.url,
postCaption = post.caption ? post.caption.text : '';
html += [
'<li>',
'<a href="' + postLink + '" target="_blank">',
'<img src="' + postImage + '" alt="' + postCaption + '">',
'</a>',
'</li>'
].join('');
}
$( html ).appendTo( settings.postsEl );
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment