FB Graph API:通过API获取对象字段列表的方法

时间:2013-04-19 00:08:00

标签: facebook facebook-graph-api

有没有办法以编程方式获取特定facebook对象的字段列表?

我知道有相关的文档,但我需要一些内省 - 我们正在构建一个工具,使用户能够从现有字段中进行选择。

我的意思是:给我一个用户字段列表,回复:{“id”,“name”,“first_name”,...}

或者某种方式如何获取一个对象的所有字段并从中派生出来?

1 个答案:

答案 0 :(得分:8)

Facebook允许您传递metadata = 1参数。例如

cocacola?metadata=1

为您提供该页面的所有可用连接和字段:

  "metadata": {
    "connections": {
      "admins": "https://graph.facebook.com/cocacola/admins",
      "admin_settings": "https://graph.facebook.com/cocacola/admin_settings"
    },
    "fields": [
      {
        "name": "id",
        "description": "The Page's ID. No access token or user `access_token`. `string`."
      },
      {
        "name": "name",
        "description": "The Page's name. No access token or user `access_token`. `string`."
      },
      {
        "name": "link",
        "description": "Link to the page on Facebook. No access token or user `access_token`. `string` containing a valid URL."
      },
      {
        "name": "category_lists",
        "description": "The Page's categories. No access token or user `access_token`. `string`."
      },
      {
        "name": "is_published",
        "description": "Indicates whether the page is published and visible to non-admins. No access token or user `access_token`. `boolean`."
      }

看起来像是官方的,在getting started manual

中找到了