dqtl46964
2015-11-06 12:54 阅读 85
已采纳

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 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

    点赞 评论 复制链接分享

相关推荐