Sig
Sig

Reputation: 5948

retrieving latest post from Tumblr via jquery

I'm trying to integrate a Tumblr blog into a website. Specifically I want to display the latest text post.

I have taken a look of Tumblr API and everything looks quite easy but I cannot make it work.

According to the documentation for Tumblr API v2 (http://www.tumblr.com/docs/en/api/v2) this is the call I need:

http://api.tumblr.com/v2/blog/blog.tumblr.com/posts/text?api_key=KEY&limit=1 and if I put it in my browser I get what I want.

However if I try to retrieve the post'title to it using jquery 1.7.1 as specified below

$.getJSON('http://api.tumblr.com/v2/blog/blog.tumblr.com/posts/text?api_key=<KEY>&limit=1', function(data) {
  console.log("data.posts[0].title");
});

I get an empty response.

Am I missing something?

Thanks for your help.

SIG

Upvotes: 3

Views: 2706

Answers (2)

Jisha Muthuswamy
Jisha Muthuswamy

Reputation: 41

The solution given by Andreas is worked for me. I changed the code with $.ajax and data type to JSONP. Now I am able to get the data from tumblr.

$.ajax({
    type: "GET",
    url: "http://api.tumblr.com/v2/blog/blog.tumblr.com/posts/text?api_key=<KEY>&limit=1",               
    dataType: "JSONP",
    success: SuccessCallbackFunction,
    error: ErrorCallbackFunction,
});

Upvotes: 1

Andreas
Andreas

Reputation: 21881

You have to use JSONP as of the Same-Origin-Policy

How to do this you can read in the documentation in the Response Format section.

Upvotes: 2

Related Questions