Skip to content

Instantly share code, notes, and snippets.

@heytomsmith
Last active November 13, 2015 15:48
Show Gist options
  • Save heytomsmith/2688a2f3be628159a4c1 to your computer and use it in GitHub Desktop.
Save heytomsmith/2688a2f3be628159a4c1 to your computer and use it in GitHub Desktop.
Get Tumblr Post Data
function getNotes(id){ // Example function, can be getWhateverYouWant()
var blogName = 'YOUR_BLOG_URL'; // something.tumblr.com
var apiKey = 'YOUR_API_KEY'; // Obtained from tumblr
return $.ajax({
type: 'GET',
url: 'http://api.tumblr.com/v2/blog/'+blogName+'/posts?id='+id+'&api_key='+apiKey,
data: {
get_param: 'value'
},
dataType: 'jsonp',
success: function(data) {
console.log(data.response) // Shows you the object/arrays available to you
// Example pull would be console.log(data.response.posts[0].post_notes)
}
});
}
function getPostsData(el) {
var $elems = $(el); // Example: for all posts on page 'el' would be $('.your-post-class')
var $elemsIDs = $elems.map(function () {
return this.id; // Map all post id's to an array
}).get();
totalPosts = $elemsIDs.length;
for (i=0; i < totalPosts; i++) { // loop through the array
getNotes($elemsIDs[i]); // For each, run ajax call
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment