Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing result field in GET requests of the Facebook GRAPH API

I'm trying to access the number of likes, shares and comments a given URL has received on facebook.

As I understand this piece of doc, the following URL should give me what I want.

https://graph.facebook.com/v2.4?id=http://stackoverflow.com&fields=og_object,share&access_token=MY_ACCESS_TOKEN

It gives me the following :

{
"og_object": {
   "id": "10150180465825637",
   "description": "Q&A for professional and enthusiast programmers",
   "title": "Stack Overflow",
   "type": "website",
   "updated_time": "2015-08-02T04:03:47+0000",
   "url": "http://stackoverflow.com/"
},
"share": {
   "comment_count": 4,
   "share_count": 32567
},
"id": "http://stackoverflow.com"
}

which includes comment_count = 4 and share_count = 32567.

But, if I refer to the previously linked piece of doc, the number of likes should appear in "og_object" : there should be an engagement line with two elements inside, count (the number of likes) and social_sentence (a social sentence such as "You and 31,608,561 others like this.")

Obviously, these engagement and count elements are not there. How can I have them appear ?



NB : in the first URL, I tried changing the &fields=og_object,share part for any of these :

&fields=og_object.engagement,share
&fields=og_object.engagement.count,share
&fields=og_object,engagement,share
&fields=og_object,engagement,share
&fields=engagement,share
&fields=engagement.count,share
&fields=engagement,count,share
&fields=count,share

(NB : I also tried by putting `share` first in the list)

but none of them worked, I always get an error such as this one (every try which include a .) :

{
   "error": {
      "message": "Syntax error \"Expected \"(\" instead of \",\".\" at character 20: og_object.engagement,share",
      "type": "OAuthException",
      "code": 2500
   }
}

or this one (every try without a . :

{
   "error": {
      "message": "(#100) Tried accessing nonexisting field (engagement) on node type (URL)",
      "type": "OAuthException",
      "code": 100
   }
}
like image 917
François M. Avatar asked Aug 02 '15 04:08

François M.


1 Answers

Thanks to @WizKid, the answer is

https://graph.facebook.com/v2.4?id=http://stackoverflow.com&fields=og_object{engagement},share&access_token=

or

https://graph.facebook.com/v2.4?id=http://stackoverflow.com&fields=og_object{engagement{count}},share&access_token=

However, og_object{engagement{count}} and share_count display the same number... which is equal to the total_count when using the good old (& deprecated)

http://api.facebook.com/restserver.php?method=links.getStats&format=json&urls=h‌​ttp://stackoverflow.com/

It seems there is no way to get the number of likes and the number of shares with the graph api...

like image 170
François M. Avatar answered Nov 05 '22 05:11

François M.