Any Method to Get number of LIKES of a URL or PAGE of Facebook? - facebook-graph-api

i am trying to show number of likes on my website of my page but i dont want that facebook widget. Please help me - Any API Request that i can use to pull number of likes.
Thanks in advance

Yes, you can do this easily with Facebook Graph API.
There are two options:
if you want to get number of likes of some Page or URL, use this piece of code:
https://api.facebook.com/method/fql.query?query=select%20like_count%20from%20link_stat%20where%20url=%27http://www.facebook.com/facebook/%27&format=json
NOTE that you need to change the part where i wrote URL that's http://www.facebook.com/facebook
The New Graph API provides a minimal pull request code e.g.
http://graph.facebook.com/[Type your Page USERNAME here]?fields=likes
Here replace [Type your page username] part with username e.g.
http://graph.facebook.com/facebook?fields=likes`
and it will give you an output like:
{
"id": "20531316728",
"likes": 92990262
}
I hope this helps and fulfills your purpose.

Related

How to determine why a facebook page URL will not return a facebook id?

For the most part, using the graph api, passing in a Facebook page's encoded URL returns the normal facebook id.
For instance, using the Graph API Explorer and passing in https%3A%2F%2Fwww.facebook.com%2Fkendalljenner returns
{
"name": "Kendall Jenner",
"id": "173567062703796"
}
However, for some (pretty rare) FB pages, like http%3A%2F%2Fwww.facebook.com%2Fmargotrobbie, I get
{ "id": "http://www.facebook.com/margotrobbie" }
The question, Why do some Facebook urls not return their Facebook page id through graph api?, suggests that the issue may be that the page is restricted somehow (like for alcohol content). I believe this may be the case, because the Harley Quinn videos in the posts are a bit graphic, but I searched all the info for the page and it doesn't say anything about the content being restricted. In addition, I am using a User access token that is allowed to see the page via normal FB web interface without any apparent restriction.
BTW, for anyone who hasn't seen this before, the id set to the url seems to be the result when facebook doesn't know anything about the URL. Obviously this shouldn't be the case for facebook's own URL.
Not sure what the reason for the apparent difference with the two page URLs indicated, but I did solve the underlying problem of getting the facebook id of the page!
First of all, I had tried the process described here: How to get page id of facebook page, however it wasn't working for me. In my effort to permute all options, I had changed the access token to a "user access token". Turns out, you HAVE to have an "application access token" as is well-documented in said article.
Thanks to CBroe for making me question how I was calling the API...no matter how long I was calling it this way.

How to get post information

How I can get informations from post ID of any page?
I try to get it with php sdk graph but I fuiled every times.
that what I want :
Just put ID of post from any page to get informations (page, img, quote, created date, ... ).
thanks.
Your Facebook app needs the Page Public Content Access Feature. Then your can fetch post information from any page, but depending on your use case it may be hard to get a positive review.

Use FB API to get the pages that a page likes?

I've been looking at the documentation for the FB API as it pertains to pages to see if I can get the pages that given page likes and all I can see is a field that lets you get the number of users who like a given page. But, I can't seem to find a field that returns an array containing the ids and names of pages that the page itself likes. This works fine in the API explorer when trying to get the likes of a users.
I just use GET
/me?fields=likes
But, for a page... it doesn't seem to work.
Any ideas?
Put page id, instead of me:
https://graph.facebook.com/PAGE_ID/likes
Example: https://developers.facebook.com/tools/explorer/?method=GET&path=6815841748%2Flikes
Cheers

Facebook PHP SDK : Post a Check in without a PAGE_ID

I would like to know If it's possible to add a Check in on Facebook with PHP but without any Page id.
Because I have a database with a lot of places but I do not have a corresponding Facebook Page Id.
ANy idea?
To my knowledge, it is not possible to do a Check In without a page_id.
You can refer to How to get place_id before checkin? to find out how to get Facebook Page Id for your places.

using POST request on Facebook Graph API

I want to access graph API to get the number of shares for different pages of my website. I can use the GET method to do so but I want to use POST so that I can send more url in a single request. The current implementation I have for GET is
http://graph.facebook.com/?ids=http://umairj.com/,http://umairj.com/146/how-to-clear-facebook-shares-cache/
Can anyone please help ?
This is badly documented (I mean I didn't find the information when I looked for it!), but there is way to pass all the parameters to the Graph API through POST method:
in your example, you should POST to http://graph.facebook.com/
with the following DATA:
ids=http://umairj.com/,http://umairj.com/146/how-to-clear-facebook-shares-cache/&method=GET
I'm not sure about the encoding of the POST DATA..in our case, we were just using ids=.....,.....,..... with numeric FB user ids and we didn't need to do any encoding, but you might need some url-encoding
Don't forget the &method=GET or it won't work ! It helped me break the url length limit that was causing bugs on Internet Explorer (I think RFC says 1024 characters, all browsers support much more, IE only ~4096 ) when we were passing too many ids through GET
if you wish to access non-public information, the same trick works with https://graph.facebook.com/ , provided you add &session_token=***** to your query
You can try to run a FQL query to get the stats for multiple urls. Facebook link_stat documentation has an example of how to do this. I'm pretty sure you can't POST to either the FQL query or the graph api you were using though unfortunately. Your FQL query would be:
SELECT url, share_count, like_count FROM link_stat WHERE url IN("http://umairj.com/","http://umairj.com/146/how-to-clear-facebook-shares-cache/")
Here is the url after properly url encoding the query: https://api.facebook.com/method/fql.query?query=SELECT+url%2C+share_count%2C+like_count+FROM+link_stat+WHERE+url+IN%28"http%3A%2F%2Fumairj.com%2F"%2C"http%3A%2F%2Fumairj.com%2F146%2Fhow-to-clear-facebook-shares-cache%2F"%29&format=json
Facebook provides a FQL testing tool to help.
Update: their API documention (see section titled "Delete) mentions you can do an HTTP POST to any of their methods and set the variable method to the method you want. You could try this, although this was designed for delete and put methods not available to javascript clients. It still looks like is all url based so I'm not sure it will take a form encoded parameter like you are looking to do.
I work at Facebook and I've updated our Graph API documentation to document this work around for very large requests:
https://developers.facebook.com/docs/graph-api/using-graph-api#largerequests