简体   繁体   中英

Facebook Graph API - Get Page Notifications

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);
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM