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 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持