Werner
Werner

Reputation: 1847

Get number of likes for a webpage from facebook

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?

Upvotes: 2

Views: 2561

Answers (2)

dim
dim

Reputation: 341

  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

Upvotes: 2

Allanh
Allanh

Reputation: 507

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.

Upvotes: 0

Related Questions