-
-
Save DanCanetti/58376d6934f083d56bc588a9530d2ca9 to your computer and use it in GitHub Desktop.
User JQuery with the Tumblr API & JSONP
This file contains hidden or 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
// More explicit information + handling the result | |
$.ajax('https://api.tumblr.com/v2/blog/codingjester.tumblr.com/posts', | |
{ | |
dataType:'jsonp', | |
data: { | |
limit : 1, | |
api_key : 'your_key' | |
}, | |
success: function(posts) { | |
var postings = posts.response.posts; | |
console.log(postings); | |
var text = ''; | |
// Loop through each post in the result | |
for (var i in postings) { | |
var p = postings[i]; | |
if(p.type == 'photo'){ | |
text += '<div>' + '<a href='+ p.post_url +' target="_blank">' + '<img src=' + p.photos[0].original_size.url + '>' + '</a></div>'; | |
} | |
if(p.type == 'video'){ | |
text += '<div>' + p.player[0].embed_code + '</div>'; | |
} | |
if(p.type == 'text'){ | |
text += '<div>' + p.body + '</div>'; | |
} | |
} | |
// Append results to a div | |
$('#tumblrfeed').append(text); | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment