Created
December 6, 2014 21:00
-
-
Save tomblanchard/33def2cdc6a67e75914f to your computer and use it in GitHub Desktop.
Instagram feed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul class="instagram__items"></ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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