2

I used to get the number of likes for my webpage from facebook with:

http://api.facebook.com/restserver.php?method=links.getStats&format=json&urls=www.example.com

But this doesn't work anymore.

I tried:

https://graph.facebook.com/fql?q=SELECT%20total_count%20FROM%20link_stat%20WHERE%20url=%22www.example.com%22

But this doesn't work either.

I tried:

http://graph.facebook.com/?ids=http%3a%2f%2fwww.example.com

But this gives me only the share_count, not the number of likes.

I found this: https://developers.facebook.com/docs/graph-api/reference/v2.7/object/likes

POST graph.facebook.com/v2.7/{object-id}/likes HTTP/1.1

But I got no idea what the {object-id} is or where I can get it. And I don't know if I need any access-credentials to access the information.

Anyone got a small example what http-requests I need now to get the likes of my webpage please?

Werner
  • 1,695
  • 3
  • 21
  • 42
  • Possible duplicate of [Get Facebook share/like/comment count of URL](http://stackoverflow.com/questions/39028734/get-facebook-share-like-comment-count-of-url) – dim Nov 23 '16 at 08:31

2 Answers2

2
  1. receive the number of shares/comments and object-id

    graph.facebook.com/?fields=og_object{id},share&id=https://stackoverflow.com/

  2. save shares/comments count

  3. save fb object-id of url

    og_object->id

  4. get likes count with (max limit is 1000, then you can use paging):

    graph.facebook.com/OBJECT_ID/likes?access_token=ACCESS_TOKEN&pretty=1&limit=1000

UPD 2016-08-22

I found a solution that allows you to get the number of likes/reposts/comments in one step:

https://graph.facebook.com/?fields=og_object{likes.limit(0).summary(true)},share&ids=http://google.com,http://twitter.com

Community
  • 1
  • 1
dim
  • 310
  • 2
  • 8
0

First You need the Id for the page. You can to use the next page. http://findmyfbid.com/ There is you put the link of facebook page that You need for example.

https://www.facebook.com/BooStore1

and the result is:

149955492088239

Now you're going to the api graph of facebook and you need yo use the field "fan_count" This would look like

**149955492088239?fields=fan_count**

Results:

 {
  "fan_count": 110,  
  "id": "149955492088239"
 }

Note: first step is optional, You can to use the name in facebook page url that you need.

Allanh
  • 465
  • 1
  • 7
  • 19
  • Thanks for your reply. When entering my webpage (www.example.com) on http://findmyfbid.com/, I get "Error - Sorry, we could not find your Facebook numeric ID." I want to get the likes of my webpage, not my facebook-page. – Werner Aug 19 '16 at 06:53
  • What do you mean by "go to the api graph"? When doing something like: https://graph.facebook.com/www.example.com?fields=fan_count I get "Error - An access token is required to request this resource." – Werner Aug 19 '16 at 06:54
  • OK, when You're going to this page. [Link for enter to Graph api](https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=%7Buser-id%7D&version=v2.6) This is the Graph Api from facebook. When you're there you just need enter the code what I said in the answer. You need an access token for realice this action. You should to read documentation about access token here. [lDocumentation](https://developers.facebook.com/docs/facebook-login/access-tokens/) – Allanh Aug 19 '16 at 16:19