How to get Facebook page links + like count for each? - facebook

How do I get the links posted in a Facebook page AND the # of likes that link got without making extra calls?
Right now I am making this call, and it gives me all the posts that are links, posted in a Facebook page. How do I get the like count for each post? I simply want to know how many people liked that post.
https://graph.facebook.com/#{facebookId}/links?access_token=TOKEN&limit=20

To get the likes count for each post that is a link, the following query:
https://graph.facebook.com/#{facebookId}/links?fields=likes.limit(1).summary(true)&access_token=TOKEN&limit=20
gives you a response like this:
{
"data": [
{
"id":
"created_time:"
"likes": {
...
"summary": {
"total_count": 23
}
}
},
{
...
}
]
}
The total_count value is what you want.

Related

Retrieve Facebook reviews likes via Graph API

I am trying to retrieve some reviews data from Graph API, including comments, sub-comments, etc.
I can get like_count on comments using the endpoint with these parameters:
{page-id}/ratings?fields=open_graph_story{comments{like_count}}
Or the same thing with sub-comments:
{page-id}/ratings?fields=open_graph_story{comments{comments{like_count}}}
But I can't seem to find how to get them for the review itself.
I tried this:
{page-id}/ratings?fields=open_graph_story,like_count
And this (which throws an error):
{page-id}/ratings?fields=open_graph_story{like_count}
Just to be clear: in this question I separated the calls for likes on comments/sub-comments, but in reality, I'm getting all the data in a single call like this:
{page-id}/ratings?access_token={access-token}&fields=open_graph_story{comments{created_time,from,message,comments{created_time,from,message,like_count,user_likes},like_count,user_likes}},rating,review_text,created_time,reviewer
try
graph.facebook.com/open_graph_story_id?fields=likes
should return a payload structured similar to below
{
"likes": {
"data": [
],
"can_like": true,
"count": 0,
"user_likes": false
},
"id": "open_graph_story_id"
}

FACEBOOK API: Get likes of particular post on page

I want to get likes on post on the page: "The Jungle Book"
I am able to get the likes of the page using url:
https://graph.facebook.com/" + pageId + "?fields=likes&access_token=" + ACCESS_TOKEN
I have read the documentation
and find that i will get the likes(total count) of the post only returned when the flag summary=true is set
The response should look like this
{
"likes": <somecount>,
"id": "151505938209071_1507814655911519"
}
I am able to get the likes on page but not able to get total number of likes on the particular post on that page.
Can anyone help me regarding how I should set the URL or is there any other way to do it.
From what you described it sounds like it should be like this:
https://graph.facebook.com/" + pageId + "?fields=likes&summary=true&access_token=" + ACCESS_TOKEN
The above is your existing URL with summary=true in between the fields=likes and access_token parameters
However you may be interested in this answer
Quote:
Couldn't find this in the documentation but multiple calls to the API are not necessary. You can use summary when querying a feed or multiple posts. Specify this in the fields parameter.
https://graph.facebook.com/PAGE_ID/feed?fields=comments.limit(1).summary(true),likes.limit(1).summary(true)
This will return a response like this.
{
"data": [
{
....
"summary": {
"total_count": 56
}
...
},
{
....
"summary": {
"total_count": 88
}
...
}
]
}
This will be much faster than making individual requests for each object just to get the number of comments or likes.

Facebook Batch returns: Some of the aliases you requested do not exist

I'm building this batch in order to get all the share counts for all the pictures in an album (and like and comments on each photo):
My Batch:
[
{
"method":"GET",
"name":"get-photos",
"relative_url":"951337131548012?fields=photos.limit(250){likes.limit(1),comments.limit(1),id,source,page_story_id},likes.limit(1)"
},
{
"method":"GET",
"relative_url":"{result=get-photos:$.photos.data.*.page_story_id}?fields=shares"
}
]
It always returns Some of the aliases you requested do not exist with the page_story_id number, but when i'm querying the graph api for that story id i get the data..
any ideas why ?
As I answered my question asked here: Facebook Api v2.2 - get album's photos shares count
The right batch request should be:
[
{
"method":"GET",
"name":"get-photos",
"relative_url":"951337131548012?fields=photos.limit(250){likes.limit(1),comments.limit(1),id,source,page_story_id},likes.limit(1)"
},
{
"method":"GET",
"relative_url":"/?ids={result=get-photos:$.photos.data.*.page_story_id}&fields=shares"
}
]

Missing Photos from Timeline Photos album

I'm using Facebook Graph API to get all the photos of a user graphPath: me/albums and find something weird with Timeline Photos album.
Photos exist in Timeline album on Facebook, but not returned from API call graphPath/{timeline_photos_album_id}/photos, or they are returned with lower number of photos.
What is the problem?
Logs:
Calling for albums graphPath: me/albums:
.....
{
"can_upload" = 0;
count = 3; !!!!!!!!!!!
"created_time" = "2013-06-18T10:43:27+0000";
description = cool;
from = {
id = 100006100533891;
name = "Mike Mike";
};
id = 1387760311437307;
link = "https://www.facebook.com/album.php?
fbid=1387760311437307&id=100006100533891&aid=1073741829";
name = "Timeline Photos";
privacy = everyone;
type = wall;
"updated_time" = "2013-06-18T10:47:53+0000”;
},
.....
Calling for album photos graphPath/{timeline_photos_album_id}/photos:
{
data = (
);
}
Unfortunately "it is not a bug, it is by design".
I tried the following (with "user_photos" permission) and it works:
Fetch the album photo count for my user:
https://graph.facebook.com/me/albums?fields=id,count&access_token={access_token}
The result is
{
"data": [
{
"id": "{album_id}",
"count": 161,
"created_time": "2010-11-05T15:41:42+0000"
},
....
}
Then query for the photos of this album:
https://graph.facebook.com/{album_id}/photos?fields=id&limit=500&access_token={access_token}
The result is
{
"data": [
{
"id": "{photo_id1}",
"created_time": "2013-12-29T09:59:52+0000"
},
{
"id": "{photo_id2}",
"created_time": "2013-12-17T10:40:26+0000"
},
...
}
I count the correct number of 161 ids in the result. So everything seems to work fine.
You can also test this via FQL:
https://graph.facebook.com/fql?q=select+pid+from+photo+where+album_object_id+=+{album_id}+limit+1000&access_token={access_token}
there have been changes in the FB API recently, did you try to add the fields you want to get back in the result from the API? In the past, API always returned "standard fields", newest you always have to provide a list of fields of what you want to have back in the result such as ....fields=name,id...
I think you are missing the user_photos permission in the Access Token. The end point:
/{timeline_photos_album_id}/photos is working perfectly fine for me when I tried it using the Graph API Explorer to retrieve photos from my Timeline photos album. And, I don't think that it is necessary to provide the fields.
I'll suggest you should try the same using the Graph API Explorer. Just press the Get Access Token button on the top right and check the user_photos permission to test your request.
In case you are getting lesser results, you can try your query using pagination options limit and offset. This sometimes returns more results as compare to normal(nothing about this on docs, just my personal experience). Something like:
{timeline_photo_album_id}/photos?limit=500&offset=0
But again, as you pointed out, there are strange things going on with the API. Take a look at this article. This article refers to it as an expected behavior of the API!

FaceBook API for friends count

There is the question about fetching count of user friends via FaceBook API.
I want to get the number of friends only have USER_ID of the any facebook user. As I know I can get it using FQL like:
SELECT friend_count FROM user WHERE uid = X
But for some users this value is null or there is no value. Please advice is there another way to get this value?
That user might be keeping that information private. In that case, you cannot fetch that information.
You just check the following link. You need to generate token (by clicking on Get Token you will get it) with data you want from facebook API, need to select friends option to get the friend count.
https://developers.facebook.com/tools/explorer/?method=GET&path=me%3Ffields%3Did%2Cname%2Cfriends&version=v2.8
FB.api(
'/me',
'GET',
{"fields":"id,name,friends,link,email,gender,picture,first_name,last_name,cover"},
function(response) {
// Insert your code here
}
);
after executing this you will get this in response as
{
"id": "XXXXXXXXXX",
"name": "Test test",
"friends": {
"data": [
],
"summary": {
"total_count": 14
}
}
}
total_count will be your friend count