0

一些 Facebook 图形 API 端点返回如下数组:

"likes": {
    "data": [
      {
        "id": "000000", 
        "name": "Somebody"
      }
    ], 
    "paging": {
      "cursors": {
        "after": ".....", 
        "before": "....."
      }
    }
}

而其他人则返回这样的数组:

"actions": [
    {
      "name": "Comment", 
      "link": "https://www.facebook.com/000000/posts/00000"
    }, 
    {
      "name": "Like", 
      "link": "https://www.facebook.com/00000/posts/00000"
    }
  ] 

有谁知道 Facebook 在文档中的哪个位置解释了何时将数组返回包装在一个{ data: [...] }对象中?据我所知,facebook 只列出了数组中的所有内容,array并没有解释何时返回数据对象。

我想我可以假设如果可以“分页”某些东西,它将位于数据结构中......

我是否在某处遗漏了一些关于 Facebook 数据类型的文档?

4

2 回答 2

0

You are right, they seem to list everything that is an array as array.

For instance, in the documentation for the Post Endpoint, the return type for both "likes" and "actions" is listed as an array.

Likes   
...
Array of objects containing the id and name fields. 
Requesting with summary=1 will also return a summary object 
containing the total_count of likes.

Actions
...
Array of objects containing the name and link

I think that's why you have to query the actual end point, and inspect the JSON (like you are doing) and figure out what is actually coming back.

No wonder the Facebook API is the proud winner of the "Worst API" Award!

于 2013-11-06T23:25:25.217 回答
0

您检索到的任何提要(提要/帖子)(即每个数组)都将在data对象中返回,在此data对象内,数组将在那里。此外,朋友列表嵌入在data对象中,该对象将具有对象数组。像这样的东西:

{"data": [
      {
        "id": "..", 
        "name": ".."
      }
    ], 
    "paging": {
      "cursors": {
        "after": ".....", 
        "before": "....."
      }
    }
}

而在所有其他不返回数组的 api 请求中,具有如下结构:

   {
        "id": "..", 
        "name": ".."
      }
于 2013-11-07T04:12:52.020 回答