Since today when I try to get the share count the answer is :share field is deprecated for versions v2.9 and higher.
Ex with : https://graph.facebook.com/?id=https://stackoverflow.com&fields=share
Without &fields=share the json content is displayed but without the share value.
I need to get the share count Facebook from an url.
4
Answers
The API has changed indeed.
It should be like this.
https://graph.facebook.com/?id=https://stackoverflow.com&fields=engagement&access_token=user-access-token
You need an access token. If you have a Facebook, go to https://developers.facebook.com/ and make an app.
Graph API Explorer
Then click “Graph API Explorer”.
Get Token
and “Get Token” (Get App Token). That’s it.
If you use JavaScript for a count, it’s will be something like this.
There are other count types such as comment_count and share_count.
See https://developers.facebook.com/docs/graph-api/reference/v3.2/url
Is there any way to receive a count without sending an access token?
I wanna know that myself lol
UPDATE:
Thanks to Anton Lukin.
Yeah. I shouldn’t show an access token. It must be hidden. I feel very foolish.
So now quick’s answer. This really works without the token!
My final (I hope will be final) answer is like this.
One point here is that when nobody has ever shared the targeted page, ‘og_object.engagement’ isn’t even defined.
I thought I’d get 0 as a return valule. But that’s not the case.
So let’s use try-catch.
Now my only concern is API Limits. If your site gets a lot of pageviews, this updated version may not work..
Since you can’t display your access token on front-end, I suggest you to proxy requests with nginx, hidding your access_token on your server.
You need an access token. Navigate to https://developers.facebook.com/ and make an app.
Go to Graph explorer and copy the token. To obtain permanent token follow this short guide
Add custom rule to your nginx config
If you do not want use access token or nginx proxy solution, see https://stackoverflow.com/a/45796935/2424880:
You can use the query
The answer will be
UPDATE 2021: You need access token for this request. You can get temporary access token in Graph API Explorer or generate it with your custom app
If you have app in facebook, its very simple without login, you can get it.
Response will be like :
Ref : https://developers.facebook.com/docs/facebook-login/access-tokens