Skip to content

Instantly share code, notes, and snippets.

@DanCanetti
Forked from codingjester/ajax_jsonp.js
Last active August 6, 2020 15:32
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 DanCanetti/58376d6934f083d56bc588a9530d2ca9 to your computer and use it in GitHub Desktop.
Save DanCanetti/58376d6934f083d56bc588a9530d2ca9 to your computer and use it in GitHub Desktop.
User JQuery with the Tumblr API & JSONP
// 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