Facebook Api v2.2 - get album's photos shares count - facebook

I'm using the following Graph Api query in order to receive the likes and comments counts on all the photos in an Album inside my page:
https://graph.facebook.com/v2.2/album_id?fields=photos.limit(250){likes.limit(1),comments.limit(1),id,source},likes.limit(1)&access_token=my_access_token
I want to to also receive each one of these pictures shares count, but the share count is not connected to the photo end point, Its connected to the page_story_id.
So, in order to receive all the shares count i'm going to need to query each of those individually, which doesn't make sense when you have an album with 200 pictures (not to mention an album with 500 pictures).
FQL is deprecated after v2.1 so I can't use the FQL to get this (which will defiantly ease everything for me).
Isn't there an easier way to do so?
Update
Thanks to #CBroe comments, this is 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":"/?ids={result=get-photos:$.photos.data.*.page_story_id}"
}
]
Now it does return all the photos post objects, but how can I query them all the specific field? like add ?fields=shares

ok after struggling with this for few hours, and thank to #CBroe help I found the right batch request for my needs and it involves both batch and Graph API multiple requests.
[
{
"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"
}
]
by adding &fields=shares i'm filtering the fields of inner results of the multi request.
Hope it helps someone :)

Related

Retreiving facebook comments by API

I would like to maintain a copy of all Facebook comments on my business page for analysis purposes.
I created an app and tokens and managed to query all posts on the page by this call
https://graph.facebook.com/v11.0/{page-id}/feed?access_token={token}
And for every post I can get the full comments by this call:
https://graph.facebook.com/v11.0/{object-id}/comments?summary=1&filter=stream&order=reverse_chronological&access_token={token}
That worked great but I have two problems:
I would like to retrieve all new comments on all posts. My page has 500+ posts. It would be very wasteful to query each of the 500 pages on daily basis to get all comments because 490+ of them will probably have no new comments on an any given day.
The results from the comment API call is very basis and does not provide the user name like the below sample
{
"data": [
{
"created_time": "2021-06-10T23:52:09+0000",
"message": "test 3",
"id": "xxxx_xxxx"
},
Is there a way to retrieve all comments regardless of the page and provide more info in the result? There are commercial tools that perform similar functionality like Sudota so theoritcally it should be possible but I could not find that in the API documentation.

Facebook Graph API: unable to get shared posts although share count is higher than zero

I'm experiencing a weird behavior from the graph API: i want to list shares of a shared posts, so i'm requesting /<post_id>/sharedposts?fields=shares to get the number of times a shared posts has been subsequentially shared.
The response i'm getting, thus, is a list of objects like this:
{
"shares": {
"count": 1
},
"id": "136178893505927_155012298289253"
},
However, if i request /136178893505927_155012298289253/sharedposts, I get
{
"data": [
]
}
Which is weird, as I was expecting one object to be in the response.
Moreover, if I request /<post_id>/sharedposts?fields=shares,sharedposts i'm getting a weird list containing shares.count higher than 0 and no sharedposts content in some cases and a sharedposts array containing less elements than shares.count in some others.
I'm guessing this happens because the shared posts are not visible to my profile, but shouldn't I be able to see them, since the original post was published on a page I manage?
I'm trying to build the graph of shares to determine if a share being re-shared contributed more than others to the overall share count, but it looks like this is not feasible with the graph API...or am I missing something?
Use Graph api v2.3 and you need read_stream permission.
This permission is only in this version.

facebook graph API endpoint for getting "likes, shares, comments" for post(s)

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";

Why do I get this error when I try to access a certain type of object via the Facebook Graph API?

I have a user, user_2. There is a post on their wall, made by user_1.
The URL is
https://www.facebook.com/user_1/posts/10150166228506188
I try to get the content using the Graph API, with this request:
https://graph.facebook.com/10150166228506188?access_token=ACCESSTOKENUSER_2
I get this error:
{
"error": {
"type": "GraphMethodException",
"message": "Unsupported get request."
}
}
The access_token I am using is good, because requests to get things like statuses & images work fine:
https://graph.facebook.com/10150233707783933?access_token=ACCESSTOKENUSER_2
Result:
{
"id": "10150233707783933",
"from": {
"name": "American Steel",
"category": "Professional sports team",
"id": "203692078932"
},
"tags": {
"data": [
etc
The error seems to happen whenever I try to get items that have this kind of URL:
https://www.facebook.com/username/posts/item_id
The permissions my app has include these:
Why is this error occurring?
I think that, in order to access the posts directly through the graph api, you have to prepend the user id to the post id you see in the facebook url.
So in your example the facebook post url is :
https://www.facebook.com/user_1/posts/10150166228506188
And you try to get through the graph api :
https://graph.facebook.com/10150166228506188?access_token=ACCESSTOKENUSER_2
BUT you should be doing :
https://graph.facebook.com/{id of user_1}_10150166228506188?access_token=ACCESSTOKENUSER_2
I noticed that all posts ids are formed like this by visiting :
https://graph.facebook.com/me/posts?access_token=...
Does this solve your problem ?
You're accessing the end-point of the post incorrectly. Every object on Facebook has a unique ID. Right now, it just so happens that they form it by appending different IDs together (your post is an example, <user_id>_<post_id>, and for a comment on that post it'd be <user_id>_<post_id>_<comment_id>). Facebook hasn't made public acknowledgment of this (not that they really have to, it's obvious) which makes me leary to rely on that paradigm for accessing data within the graph. This is because Facebook could change it at any point, and the fact that they haven't said "yeah append these 2 ids together and you can get something meaningful from this part of the graph" means they won't have to notify anyone about the change, you could just wake up one day and your app be completely broken and you'd have to find a work around quickly and while suffering down time.
The graph api works by accessing objects on Facebook by making a request to the API for that unique ID. So, you don't need to access (and can't access) your posts by going to graph.facebook.com/<user_id>/posts/<post_id>. Instead, you go to graph.facebook.com/<post_id>. You get the post_id from the /<user_id>/home or /<user_id>/feed end-point on the graph. There is no need to modify a post_id in order to fetch information about it from the graph.
Hope that helps

How do I retrieve photos from a Facebook group using the GraphAPI?

I would like to retrieve photos from a facebook group using the GraphAPI. Based on FB Docs I don't see any connections to photos. I would like to get the photos and the users who uploaded them.
Graph API:
http://graph.facebook.com/GROUP_ID/?fields=name,description,albums
return
{
"name": "Group name",
"description": "Group description",
"id": "GROUP_ID",
"albums": {
"data": [
{
"id": "GROUP_ALBUM_ID",
"name": "GROUP_ALBUM_NAME",
"link": "GROUP_ALBUM_LINK",
"created": 1352388257,
"modified": 1352388257,
"cover_pid": 444427468954616,
"count": 22
}
],
"paging": {
"next": "https://graph.facebook.com/GROUP_ID/albums?limit=25&offset=25"
}
}
}
and next query
http://graph.facebook.com/GROUP_ALBUM_ID/photos?fields=picture,source,name&type=uploaded
Ive been digging a bit in the same issue.
We have a group album which is has this url
https://www.facebook.com/media/set/?set=oa.10150651435446985
So the ID seems to be oa.10150651435446985
Another empty album gets album gets the set-id oa.10150652583791985
A note in the same group id 10150652589396985
Notice the similarity in ID's.
The direct link: http://facebook.com/10150651435446985 works to go to the album.
The album is created by user 1128233556 and the groupid is 184760601984.
Other, individual (not in an album) group photos are in "set" o.184760601984 where the digit represents the group id.
So what does "o" and "oa" stand for? a=album, o=?
Pictures have the following URL: https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-ash4/s720x720/420015_3293876662264_1128233556_33234982_110700674_n.jpg
420015_3293876662264_1128233556_33234982_110700674
??????_PHOTOID_______USER_______????_____?????????
Who can make something out of al that?
I have the same problem / here is my partial answer, which remains kind of hack :
one can retrieve photos posted on a group via the FQL group.stream or the GraphAPI group.feed (playing around with the facebook graphApi explorer or the fql query/multiquery test console).
This way you can retrieve all needed information, included a valid id to retrieve the photo, and one to retrieve the object from the graph.
BUT, this is only valid for individual photos.
since my previous answer was deleted, i won't repost it here, but remind that my similar problem is detailed in this thread FQL or GraphAPI unable to retrieve PHOTO ALBUM or VIDEO posted on a GROUP , which, if ever solved, might even as well help people for this very problem here.
Thomas
I don't think Albums in groups R treated like albums on Profile pages. The pics have aid ="0" Even if they are part of albums.
I used The Image below:
https://www.facebook.com/photo.php?fbid=10151350034089218 is the link to the image. And you can guess where I got the object_ID.
In this example 10151350034089218 is the object_ID for an image in an album for my group "T_Group" The link to the group is https://www.facebook.com/groups/217697621700825/.
You can then run the FQL query
SELECT aid
FROM photo
WHERE object_id = 10151350034089218
you'll get
aid
====
0
Even though it is part of an album "Hugh Laurie".
I tried the same FQL query with images in albums on my profile and they always returned an aid with some Number other than 0.
I plan on posting to Facebook bugs, I hope I get a fix. Unless its running as intended.
I tried:
SELECT pid
FROM photo_tag
WHERE subject =217697621700825
...and I got PIDs to photos posted to the group page not images in albums.
I wish I had found a more direct method, but this appears to have promise:
get /me/groups or /me?fields=groups to get the groups ids.
From that, get {group_id}/feed?type=photo This returns just the photos from the feed, but all you really get (toward this goal) is the photo's id (returned as object_id).
Then for each photo you can get /{object_id} which returns all the links to the various sizes of the image.
I did this research in Facebook Graph Explorer, so keep that in mind as you try to implement it.
Rob