简体   繁体   中英

facebook graph api sharedpost get amount of likes from the page that shared

I use the sharedpost endpoint to retrieve the pages that shared my post like this:

{post_id}/sharedposts?fields=likes.summary(1),id,created_time,from.summary(1)&limit=1500

This will return the data like:

{
  "id": "{sharedpost_id}",
  "created_time": "2017-05-13T23:01:51+0000",
  "from": {
    "name": "Page that shared",
    "id": "Id of page that shared"
  },
  "likes": {
    "data": [
    ],
    "summary": {
      "total_count": 0,
      "can_like": false,
      "has_liked": false
    }
  }
}

Now some posts get a shitload of shares so I want to filter only the shares by pages that have above a certain amount of likes.

Now I can make a second call to the api which asks for the amount of likes but I hope it would be possible to do this in the same request.

So The desired output would be:

 {
  "id": "{sharedpost_id}",
  "created_time": "2017-05-13T23:01:51+0000",
  "from": {
    "name": "Page that shared",
    "id": "Id of page that shared"
    "likes: : "Likes of the page that shared"
  },
  "likes": {
    "data": [
    ],
    "summary": {
      "total_count": 0,
      "can_like": false,
      "has_liked": false
    }
  }
}

So with the likes of the page included in the from.

Is this possible?

Thanks in advance!

Can be done using Field Expansion :

/post-id/sharedposts?fields=from{name,fan_count}

And if you need this not only for single posts, but for all posts in a page's feed, you can also move that “one level up”, like so:

/page-id/feed?fields=sharedposts{from{name,fan_count}}

I am not exactly sure if that still works, if you also get shared posts by users returned - in that case it might throw an error, that fan_count is not an existing field on the user object.
This would only be relevant for posts shared by users that have logged in to your app, and granted it user_posts permission (because only then would you see those posts show in the sharedposts edge in the first place) - so if that is not applicable in your situation, it will be fine; otherwise I suggest you test this case before relying on it.

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