Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get Facebook Graph api reaction summary count separately

How can I get Facebook Graph api reaction summary count separately, When I try in Graph Explorer , ex: 614689638666135_785960901539007/?fields=reactions.summary(true) I get total count and viewer_reaction, but not enough, somebody please help this ?

like image 435
Jackal Kao Avatar asked Apr 29 '16 05:04

Jackal Kao


People also ask

What data can I get from Facebook graph API?

The Graph API is the primary way to get data into and out of the Facebook platform. It's an HTTP-based API that apps can use to programmatically query data, post new stories, manage ads, upload photos, and perform a wide variety of other tasks.

Is Facebook graph API deprecated?

API Version Deprecations: As part of Facebook's Graph API and Marketing API, please note the upcoming deprecations: August 3, 2021: Graph API v3. 3 will be deprecated and removed from the platform. August 25, 2021 Marketing API v9.

Is Facebook graph API RESTful?

As you suggested, the Graph API, just like the Legacy REST API, is in fact a RESTful API.


1 Answers

You need to specifically ask for each reaction, however as mentioned in the comments, you can leverage Field aliasing.

>>> fb_get_url = 'https://graph.facebook.com/v2.6/%s' % result['id']
>>> query_pieces ['reactions.type(LIKE).limit(0).summary(true).as(like)','reactions.type(LOVE).limit(0).summary(true).as(love)','reactions.type(WOW).limit(0).summary(true).as(wow)','reactions.type(HAHA).limit(0).summary(true).as(haha)','reactions.type(SAD).limit(0).summary(true).as(sad)','reactions.type(ANGRY).limit(0).summary(true).as(angry)', 'reactions.type(THANKFUL).limit(0).summary(true).as(thankful)']
>>> full_query = ",".join(query_pieces)
>>> r = requests.request("GET", fb_get_url, params={'access_token' : my_creds['access_token'], 'fields' : full_query})
>>> print(dumps(r.json(), indent=2))
{
  "love": {
    "data": [], 
    "summary": {
      "total_count": 0, 
      "viewer_reaction": "LIKE"
    }
  }, 
  "like": {
    "data": [], 
    "summary": {
      "total_count": 1, 
      "viewer_reaction": "LIKE"
    }
  }, 
  "wow": {
    "data": [], 
    "summary": {
      "total_count": 1, 
      "viewer_reaction": "LIKE"
    }
  }, 
  "haha": {
    "data": [], 
    "summary": {
      "total_count": 0, 
      "viewer_reaction": "LIKE"
    }
  }, 
  "sad": {
    "data": [], 
    "summary": {
      "total_count": 0, 
      "viewer_reaction": "LIKE"
    }
  }, 
  "thankful": {
    "data": [], 
    "summary": {
      "total_count": 0, 
      "viewer_reaction": "LIKE"
    }
  }, 
  "id": "10100996730306423_10101331756810623", 
  "angry": {
    "data": [], 
    "summary": {
      "total_count": 0, 
      "viewer_reaction": "LIKE"
    }
  }
}
>>>
like image 98
Patrick V Avatar answered Jan 01 '23 23:01

Patrick V