dqtl46964 2015-11-06 12:54
浏览 96
已采纳

Facebook Graph API - 获取页面通知

I've just upgraded to graph api 2.5 and the PHP SDK 5.0 and it seems the way in which you get a pages notifications has changed.

In the past I could call:

/{page_id}/notifications

and get a response like this:

{
  "id": "notif_12345_12345",
  "from": {
    "name": "John Doe",
    "id": "12345"
  },
  "to": {
    "name": "Page Name",
    "category": "Community",
    "id": "12345"
  },
  "created_time": "2015-11-01T16:23:38+0000",
  "updated_time": "2015-11-01T18:10:26+0000",
  "title": "John Doe and Jane Doe commented on a link you shared.",
  "link": "http://www.facebook.com/page/posts/12345?comment_id=12345"
}

Perfect, exactly what I wanted. But in 2.5 I just get:

{
  "data": [
    {
      "to": {
        "name": "Page Name",
        "id": "12345"
      },
      "id": "notif_12345_12345"
    },
    {
      "to": {
        "name": "Page Name",
        "id": "12345"
      },
      "id": "notif_12345_67890"
    }
}

And I have no idea what to do with this? I've tried making a request for:

/notif_12345_67890

But it just returns the same info.

Is there anyway to get the notification details in the graph api these days?

For completeness sake here's what i'm doing with PHP, although the response can also be tested in the graph explorer.

$sdk = new \Facebook\Facebook([
    'app_id' => $app_id,
    'app_secret' => $app_secret,
    'default_graph_version' => 'v2.5',
]);

$response = $sdk->get($page_id.'/notifications', $access_token);

$graphEdge = $response->getGraphEdge();

// Iterate over all the GraphNode's returned from the edge
foreach ($graphEdge as $graphNode) {
    var_dump($graphNode);
}
  • 写回答

1条回答 默认 最新

  • dtevhgk028372 2015-11-06 13:04
    关注

    Since v2.4, you have to specify the fields you want to get returned:

    /{page_id}/notifications?fields=name,title,link
    

    It is a bit more complicated with subdocuments, but i believe this should work:

    /{page_id}/notifications?fields=name,title,link,to{name,category}
    

    "Declarative Fields" is what that is: https://developers.facebook.com/docs/apps/changelog#v2_4

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化