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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)