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?
receive the number of shares/comments and object-id
graph.facebook.com/?fields=og_object{id},share&id=https://stackoverflow.com/
save shares/comments count
save fb object-id of url
og_object->id
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
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.
Related
Facebook is planning to drop support for FQL after V2.0 https://developers.facebook.com/docs/apps/changelog/#v2_0_fql
The below task could be done easily with FQL
SELECT like_info.like_count, comment_info.comment_count, share_count
FROM stream
WHERE post_id = "POST_ID_HERE"
I am unable to find a replacement to the above method in graph api. I know we can get likes and comments count like
POST_ID/likes?summary=true AND
POST_ID/comments?summary=true
but I am unable to find a similar endpoint for shares.
NOTE: I am not looking for solutions that take URL input and query graph api for that URL shares, rather I am looking at finding solution to get shares count by POST_ID
PAGE_ID/feed?fields=comments.limit(1).summary(true),likes.limit(1).summary(true)
I have looked at.
Facebook API: best way to get like, share, comment count for a page/group post?
How to get Likes Count when searching Facebook Graph API with search=xxx
Facebook post comment count from Graph API
http://www.quora.com/Facebook-Graph-API/Facebook-Graph-API-How-to-get-the-number-of-likes-on-a-status
The result should be something like this:
{
"data": [{
"like_info": {
"like_count": 3506
},
"comment_info": {
"comment_count": 263
},
"share_count": 278
}]
}
Any help would be highly appreciated.
Cheers!
UPDATE: It was an access token issue as the token I was using did not have "read_stream" permission.
The field shares does not need the .summary(true) at the end. It will bring always the total. But the likes and comments does need .summary(true)
Example:
[POST_ID]?fields=shares,likes.summary(true),comments.summary(true)
Improved version works with Graph Api v2.11 (add limit(0) to removes lists of likes and comments and get only summary data):
[POST_ID]?fields=shares,likes.summary(true).limit(0),comments.summary(true).limit(0)
This will bring the total count of shares, comments and likes.
You may have a access_token with an read_stream permission to get the shares count.
Get likes, comments and shares and all 3 combined.
Check my ans : https://stackoverflow.com/a/36997725/2439715
Improved version ( add limit(0) to removes list of likes and get only summary ):
114916098537132_1265715836790480?fields=shares,likes.limit(0).summary(true),comments.limit(0).summary(true)
Get comments, shares, and likes count from post:
[POST_ID]/?fields=id,shares,likes.limit(0).summary(true),comments.limit(0).summary(true)
I've included limit(0) to prevent the API from spitting out the actual comments and likes. I believe the default limit is 25.
Please note you can also add these fields to /feed to get this data for all the posts on the page.
[PAGE_ID]/feed?fields=id,shares,likes.limit(0).summary(true),comments.limit(0).summary(true)
Final note: If shares data is missing on the return, it is because the post has no shares. Instead of returning "shares": {"count": 0}, the shares section will be removed entirely.
"https://graph.facebook.com/v2.2/PAGEid_POSTid/?
fields=shares&access_token=YOUR_ACCESS_TOKEN";
I am using above mentioned endpoint.
Replace $pageID and $videoID (post id) with your variables.
"https://graph.facebook.com/v2.2/" . $pageID."_".$video->id . "/?fields=shares&access_token=YOUR_ACCESS_TOKEN";
Calling this URL return a user object with public informations about a facebook user:
https://graph.facebook.com/100000050972893
100000050972893 is the facebook user ID. Is it possible to get multiple user objects with one call? I need to know the gender of about 200 users and I dont think its a good idea calling 200 times the graph URL...
Just found the answer:
https://graph.facebook.com/?ids=100000050972893,100000953354280
But I dont know where the Limit of IDs is you can check with one call...
My application(game) has been running on Facebook for some time. I start by requesting a friends list via the graph API call: my-uid/friends
asking for user name and profile pic.
Normally I get back a list of all my friends up to a few thousand, until it starts putting friends on to the next page. Which is nice as most of my users get friends in 1 call.
Suddenly however, and with no changes to the app. about 40 minutes ago (18:40 Tuesday (PDT) - 2nd May 2012) I started getting responses with only 25 friends per 'page'!
I can still get my whole friends list using multiple calls, but the game is not currently set up to do that properly. Can anyone tell me why the sudden change? Anyone else seen similar problems and how do I get the list to give me up to 5000 friends per page like it used to.
Reproducible using the Graph API Explorer
I don't know what else to tell you; perhaps the default number returned has changed, but when I try, a call to /me/friends?limit=5000 returns the full list for me (but my friends list is >500 and < 1000 , so maybe it cuts off somewhere along the way)
(Side note: the average number of friends has been found to be ~190 so presumably most users will have less than 500 anyway, and having to page above 500 would be an edge case
In SDK 4.7 you need to pass in a bundle with the number of friends you want to return, I have set it to 5000 as this is the maximum number of friends you can have on Facebook.
You also need to set up your app as a game in the facebook dev console and use invitable friends to get a full friends list
Create your bundle
Bundle bundle = new Bundle();
Add params to your bundle
bundle.putInt("limit", 5000);
Then pass it in to your GraphRequest
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/me/invitable_friends",
bundle,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
//Do something with the response
}
}
).executeAsync();
It seems that facebook changed its limit to 25 results in other api calls too (feed, posts, friends, etc), if you request friends without parameters the JSON response shows the following:
"paging": {
"next": "https://graph.facebook.com/USER_ID/friends?format=json&limit=25&offset=25&__after_id=LAST_ID"
}
Anyway you could/should always set limit & offset parameters to prevent this kind of things, limit = 0 will return all your friends list.
https://graph.facebook.com/USER_ID/friends?limit=0
If you are only requesting friends from a normal user the maximum number allowed is 5,000 so the limit should could be either 0 or 5,000 if you are requesting info from a facebook page or other kind of api calls like posts or feed this limit could increase or decrease.
(Update) Facebook fixed this bug so setting limit to 0 returns 0 friends, you should set a positive limit, thanks Dinuz
I think the best thing you can do is to add limit=5000 parameter as Igy says.
However I posted a bug report since this change wasn't noticed or described in the document.
The number of results returned from the /v2.2/me/friends endpoint now defaults to 25.
Friend list now only returns friends who also use your app: The list of friends returned via the /me/friends endpoint is now limited to the list of friends that have authorized your app.
See Facebook changes
Facebook API change log
If you are using GraphRequest() (e.g. in React Native), you can put it directly in the string field, like so :
new GraphRequest(
'/me',
{
accessToken,
parameters: {
fields: {
string: 'id,email,first_name,last_name,friends.limit(5000)'
}
}
...
I want to get all the comments made on facebook on a particular link.
see this image: http://cl.ly/062k1T380V1V3y2b1t0G, I want to get all 55 commments for that link. Is there any way I can do it?
I have tried graph.facebook.com/search?q=madhyamam.com, but the output is not accurate, or return null value.
You can get the url by querying all of the url's you have linked from your page:
https://api.facebook.com/method/fql.query?query=SELECT link_id, created_time, title, url FROM link WHERE owner = YOUR_FACEBOOK_PAGE_ID&access_token=YOUR_ACCESS_TOKEN
That should give you a list of your urls and their ids. With the id you should be able to get the comments to it:
https://graph.facebook.com/LINK_ID/comments
That will give you all of the info on your comments.
yoo can easily get mobile number of the user by this url https://graph.facebook.com/me?access_token=ACCESS_TOKEN......
the output comes in json format , after that you got the string , in there is value for key ..."mobile_phone"
Otherwise ,,,it is also beneficial for you https://graph.facebook.com/me?fields=address,mobile_phone&
access_token=ACCESS_TOKEN ...in this case you have to take permissions from the facebook api..
Thanks
Is there a way to retrieve the list of Facebook users that have clicked the like button on an external website?
E.g. there is a domain example.com which has been confirmed via Facebook Insights to belong to fbUser1 (using OG meta tags).
Somewhere on example.com there is a page with multiple XFBL like buttons, each one pointing to a further specific URL on example.com, e.g. example.com/xyz, example.com/abc etc.
What I'd like to get is the list of users that liked example.com/xyz and of those who liked example.com/abc.
My intuitive approach would be to look at graph.facebook.com/123456789/likes (where the number is the ID of the domain taken from FB insights), but this always returns an empty dataset:
{
"data": [
]
}
I've also tried getting an OAuth access token from https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=APPID&client_secret=APPSECRET (where APPID and APPSECRET are taken from a FB application that is marked as owning the domain using OG meta tags), but that makes no difference.
I'd also be interested in a non-OpenGraph (i.e. JS SDK, FQL etc.) solution.
EDIT: Using the following code (according to WideBlade's answer below) still gives me an empty list of likes (the second query never returns):
var objectsQuery = "select id from object_url where url in ('http://example.com/xyz', 'http://example.com/abc', 'http://example.com/123')";
var likesQuery = "select object_id from like where object_id = {0}";
FB.Data.query(objectsQuery).wait(function (objectRows) {
console.log(objectRows);
FB.Array.forEach(objectRows, function (objectRow) {
FB.Data.query(likesQuery, objectRow.object_id).wait(function (likeRows) {
console.log(likeRows);
})
});
});
FQL Should do the trick.
$facebook->api_client->fql_query('SELECT user_id FROM like WHERE object_id="OBJECTID"');
Here is the link.
Some general info about FQL.
FQL is initiated using the JavaScript SDK, in this way.
If you can post some sample code-I can try and give some more specific help.
A note should be made-once you've got the user ID's, you can just query the names and get them in a list.
EDIT: To get the URL of an object you should query this table using fql.
This cannot be done. Facebook does not allow you to query for specific user ID's of people who have liked a certain page. This is because of privacy concerns.
See the disclaimer on this page https://developers.facebook.com/docs/reference/fql/like/