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
}
}
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=http://stackoverflow.com/
It seems there is no way to get the number of likes and the number of shares with the graph api...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With