图谱 API 版

对象心情

本参考文档介绍多个图谱 API 节点常用的 /reactions 连线。每个节点的架构和操作都相同。下列对象均有 /reactions 连线:

读取

获取给对象所留心情的情况。

查看成效分析,了解与公共主页和帖子心情相关的更多信息。

新版公共主页体验

新版公共主页体验支持此端点。

要求

营销应用

  • ads_management
  • pages_read_engagement
  • pages_show_list

公共主页管理应用

  • pages_show_list

请求示例

以下是给自己对象留下了心情的用户发出的 GET 请求示例。

curl -i -X GET \
 "https://graph.facebook.com/your-post-id/reactions?access_token=your-user-access-token"
GraphRequest request = GraphRequest.newGraphPathRequest(
  accessToken,
  "/your-post-id/reactions",
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});

request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/your-post-id/reactions"
           parameters:nil
           HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/your-post-id/reactions',
  'GET',
  {},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->get(
    '/your-post-id/reactions',
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

JSON 响应

{
  "data": [
    {
      "id": "your-user-id",
      "name": "Your Name",
      "type": "HAHA"
    }
  ],
  "paging": {
    "cursors": {
      "before": "QVFIUk5YbXFFbG8yVWVOa2w0ZAGhmSUNKMkZAZAOXZARbzJOMHM0TUFtZAnhJbWdPdkF4OURUTHJrQjFqQ2RQZAVN1UGxSVU5FWURENnE4OUFPeXFreU1jV09pdFJR",
      "after": "QVFIUkpsWVRkcVl6SlhsdWlrcGdudl8xVEhwVEJ5ZA3FXdG90bTRxam13NmJDUGpQVnB5ZA29lMG9FVmFaeU1BLW1hc2oZD"
    }
  }
}

如果用户或公共主页未对查询对象留下心情,data 会显示为空。

以下是就给某个对象留下的心情总数而发出的 GET 请求示例。

curl -i -X GET \
 "https://graph.facebook.com/your-post-id
   ?fields=reactions.summary(total_count)
   &access_token=your-access-token"
GraphRequest request = GraphRequest.newGraphPathRequest(
  accessToken,
  "/your-post-id",
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});

Bundle parameters = new Bundle();
parameters.putString("fields", "reactions.summary(total_count)");
request.setParameters(parameters);
request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/your-post-id"
           parameters:@{ @"fields": @"reactions.summary(total_count)",}
           HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/your-post-id',
  'GET',
  {"fields":"reactions.summary(total_count)"},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->get(
    '/your-post-id',
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

如果用户或公共主页已给自己的对象留下心情,则会收到如下 JSON 响应。

{
  "reactions": {
    "data": [
      {
        "id": "your-user-id",
        "name": "Your Name",
        "type": "HAHA"
      }
    ],
    "paging": {
      "cursors": {
        "before": "QVFIUk5YbXFFbG8yVWVOa2w0ZAGhmSUNKMkZAZAOXZARbzJOMHM0TUFtZAnhJbWdPdkF4OURUTHJrQjFqQ2RQZAVN1UGxSVU5FWURENnE4OUFPeXFreU1jV09pdFJR",
        "after": "QVFIUkpsWVRkcVl6SlhsdWlrcGdudl8xVEhwVEJ5ZA3FXdG90bTRxam13NmJDUGpQVnB5ZA29lMG9FVmFaeU1BLW1hc2oZD"
      }
    },
    "summary": {
      "total_count": 28
    }
  },
  "id": "your-post-id"
}

如果用户或公共主页给自己的对象留下心情,则会收到如下 JSON 响应。

{
  "reactions": {
    "data": [
    ],
    "paging": {
      "cursors": {
        "before": "QVFIUk5YbXFFbG8yVWVOa2w0ZAGhmSUNKMkZAZAOXZARbzJOMHM0TUFtZAnhJbWdPdkF4OURUTHJrQjFqQ2RQZAVN1UGxSVU5FWURENnE4OUFPeXFreU1jV09pdFJR",
        "after": "QVFIUkpsWVRkcVl6SlhsdWlrcGdudl8xVEhwVEJ5ZA3FXdG90bTRxam13NmJDUGpQVnB5ZA29lMG9FVmFaeU1BLW1hc2oZD"
      }
    },
    "summary": {
      "total_count": 28
    }
  },
  "id": "your-post-id"
}

用户或公共主页只能查询自己的心情。出于隐私考虑,用户无法查询其他用户或公共主页的心情。

“like”心情计数包含“点赞”和“加油”心情。

参数

名称说明

type

enum {NONE, LIKE, LOVE, WOW, HAHA, SORRY, ANGRY}

公共主页或用户给对象标记的心情类型。

字段

读取此连线将会返回 JSON 格式的结果

{
    "data": [],
    "paging": {},
    "summary": {}
}

data

执行查询的公共主页或用户的个人主页(若该公共主页或用户已给查询对象留下心情),以及心情类型清单:

字段说明

type

enum {NONE, LIKE, LOVE, WOW, HAHA, SORRY, ANGRY}

公共主页或用户给对象标记的心情类型。

对于给帖子留下的心情,如果通过用户访问口令读取,此连线仅会返回当前用户的个人主页。

查看个别心情的数量

curl -i -X GET \
 "https://graph.facebook.com/your-object-id
   ?fields=reactions.type(LOVE).limit(0).summary(total_count)
   &access_token=your-access-token"
GraphRequest request = GraphRequest.newGraphPathRequest(
  accessToken,
  "/your-object-id",
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});

Bundle parameters = new Bundle();
parameters.putString("fields", "reactions.type(LOVE).limit(0).summary(total_count)");
request.setParameters(parameters);
request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/your-object-id"
           parameters:@{ @"fields": @"reactions.type(LOVE).limit(0).summary(total_count)",}
           HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/your-object-id',
  'GET',
  {"fields":"reactions.type(LOVE).limit(0).summary(total_count)"},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->get(
    '/your-object-id',
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

JSON 返回的示例

{
  "reactions": {
    "data": [
    ],
    "summary": {
      "total_count": 3498
    }
  },
  "id": "your-object-id"
}

paging

如需与分页相关的更多详细信息,请查看图谱 API 的分页文档。如将 limit(0) 添加至 reactions,则系统会移除输出结果中的 paging

summary

与连线相关的汇总信息,例如数量。指定要在摘要参数(例如 summary=total_count)中获取的字段。

字段说明

total_count

未签名的 int32

心情总数

viewer_reaction

enum {NONE, LIKE, LOVE, WOW, HAHA, SORRY, ANGRY}

公共主页或用户给对象标记的心情类型。

错误代码

错误说明

100

无效参数

创建

不支持此操作。

更新

不支持此操作。

删除

不支持此操作。