Graph API: Check if feed post was made by a Page or User

112 views Asked by At

When using the /page/feed endpoint in the Facebook Graph API I can't figure out how to know if the post was made by a Page or a User

Here's how I call the endpoint right now:

HTTP GET https://graph.facebook.com/v2.8/{page_id}/feed?fields=is_published,from,message

This yields the following JSON response:

{
  "data": [
          {
            "from": {
              "name": "Chad Smith", # <-- This is a User
              "id": "806273209398023"
            },
            "message": "A really magical place! Best Christmas...",
            "id": "103988597020_1445496708809010"
          },
          {
            "from": {
              "name": "Tivoli", # <-- This is a Page
              "id": "103988597020"
            },
            "message": "Hello everybody...",
            "id": "103988597020_10154040865527021"
          },
  ]
}

How can I know if the post was from a Page or User without making additional API calls? I've tried using subfields, but can't figure out if they work on the from field.

1

There are 1 answers

0
chribsen On

I solved it by using ?fields=from{name,about} and marking it as a Page if the from JSON contains about.

This is not the best solution, but about is currently the only subfield of from that doesn't fail on User. (e.g. if I was using ?fields=from{fan_count} the Graph API will fail for posts made by User objects.