如何提取的tumblr API(JSON)数据? [英] How to extract data from Tumblr API (JSON)?

查看:260
本文介绍了如何提取的tumblr API(JSON)数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经建立了一个帐户的tumblr和注册我的应用程序来验证它。

I have set up a Tumblr account and registered my application to authenticate it.

的tumblr文档: http://www.tumblr.com/docs/en/api/v2

Tumblr Documentation: http://www.tumblr.com/docs/en/api/v2

据我所知,API输出JSON是这样的:

I understand the API outputs JSON like this:

{
   "meta": {
      "status": 200,
      "msg": "OK"
   },
   "response": {
      "blog": {
         "title": "David's Log",
         "posts": 3456,
         "name": "david",
         "url": "http:\/\/david.tumblr.com\/",
         "updated": 1308953007,
         "description": "<p><strong>Mr. Karp<\/strong> is tall and skinny, with
            unflinching blue eyes a mop of brown hair.\r\n
         "ask": true,
         "ask_anon": false,
         "likes": 12345
      }
   }
}

那是罚款,但文件仅止于此。我不知道如何得到这个信息,并在我的网站显示。

Thats fine, but the documentation ends there. I have no idea how to get this information and display it on my site.

我以为你会得到它会是这样的方式:

I thought the way you would get it would be something like:

$.ajax({
    url: "http://api.tumblr.com/v2/blog/myblog.tumblr.com/info?api-key=myapikey",
    dataType: 'jsonp',
    success: function(results){
        console.log(results);
    }
});

但是,这什么也不做。

But this does nothing.

谁能帮我吗?谢谢

推荐答案

结果现在你可以使用引用JSON结构的对象。当你CONSOLE.LOG结果的对象,它应该会出现在JavaScript开发控制台,您可以探索的对象树。

results is now the object you can use to reference the JSON structure. When you console.log the results object, it should appear in the Javascript developer console where you can explore the object tree.

因此​​,当你成功回调接收响应,下面应该是提供给您:

So when your success callback receives the response, the following should be available to you:

results.meta.status => 200

results.meta.msg =>确定

results.response.title =>大卫的日志

results.response.posts => 3456

results.response.name =>大卫

results.response.url => http://david.tumblr.com /

results.response.updated => 1308953007

results.response.updated => 1308953007

results.response.description =>&LT; P&GT;&LT;强大的方式&gt;先生卡普&LT; / STRONG&GT; ..

results.response.ask =>真正

results.response.ask_anon =>假

results.response.likes => 12345

results.response.likes => 12345

如果你真的想看到的东西写你的页面,你会需要使用修改DOM等文件撰写,或功能,因为你使用jQuery $(#myDivId)。HTML (results.response.title);

If you actually want to see something written to your page you'll need to use a function that modifies the DOM such as document.write, or, since you're using Jquery, $("#myDivId").html(results.response.title);

试试这个:


  • 添加&LT; D​​IV ID =myDivId&GT;&LT; / DIV&GT; 在某处你的页面,而

  • 添加 $(#myDivId)HTML(results.response.title); 在你成功的回调函数

  • Add <div id="myDivId"></div> somewhere in the of your page, and
  • Add $("#myDivId").html(results.response.title); in your success callback function
$.ajax({
    url: "http://api.tumblr.com/v2/blog/myblog.tumblr.com/info?api_key=myapikey",
    dataType: 'jsonp',
    success: function(results){
        // Logs to your javascript console.
        console.log(results); 
        // writes the title to a div with the Id "myDivId" (ie. <div id="myDivId"></div>)
        $("#myDivId").html(results.response.title); 
    }
});

这篇关于如何提取的tumblr API(JSON)数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆