3

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

4

2 回答 2

2

Same-Origin-Policy开始,您必须使用JSONP

如何做到这一点,您可以在响应格式部分的文档中阅读。

于 2012-05-18T08:16:16.763 回答
1

Andreas 给出的解决方案对我有用。我将带有 $.ajax 的代码和数据类型更改为 JSONP。现在我可以从 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,
});
于 2013-10-08T03:12:22.420 回答