Facebook API comments count - facebook

I searched everything here and didn't find the answer.
I'm calling FB API to get some posts analytics, but I find a strange behaviour. If I call for example
134572506600855_2227601433964608/?fields=comments.limit(0).summary(true)
I get comments total_count=100
134572506600855_2227601433964608/comments?limit=0&summary=true&filter=stream
I get comments total_count=575
this is because I added filter=stream, so it counts comments-of-comments like it does in the public counter. I need to use the first call because I get all the other details there and i want to avoid an API call for each post just to get the right comments total_count, but I cannot get filter=stream working with the first call,any suggestion?

Related

FB graph API get post comments by given user

Do you know if its possible to get the list of post comments by given user?
I tried this: <post_id>/comments?fields=from.id(<user_id>) but it still returns array of all post comments. I think I have enabled all the permissions because I can see the from field but it looks like 1) the filter is not working, 2) I am doing it wrong. The graph API version I am using is v9.0
My goal is to get list of comments by given user or receive an empty array if the user didnt comment the post. Maybe there is a different way how to do it..
You cannot do this by calling the graph api anymore :/
But, there is some kind of workaround you may be able to do.
First, you'll have to set a page webhook to retrieve all the comments written on your page. Find the documentation here: https://developers.facebook.com/docs/pages/realtime
The information sent to your server via the new comment's webhook contains the "from" data, looking like this:
{
name: "Foo Bar", // the user's name
id: "12345" // A user ID (unique for your page. Will be different for the same user accross 2 different pages)
}
You may then be able to pick only the wanted user's comment
I clearly see 3 downsides to this workaround:
It only works with pages
You need to handle in realtime all the comments written on your page
You cannot retrieve the comments posted in the past

No next url for getting instagram medias on facebook's graph API for business accounts

I am trying to fetch all of my instagram page's posts (around 57k posts) from facebook's graph API. using the 'media' endpoint described here:
https://developers.facebook.com/docs/instagram-api/getting-started
I have managed to get around 12k posts using it using the query below:
https://graph.facebook.com/v3.3/{ig-user-id}/media?access_token=XXX&pretty=0&fields=timestamp,caption,comments_count,like_count,media_type,media_url,owner,permalink,shortcode,thumbnail_url,username&limit=200
when using this link returning result contains a data part which is for posts' data and a pagination section which includes next and previous urls and cursors for after and before. I used next and got remaining posts each time, until the result didn't have a next url but it had an after cursor but when I used it the data returned was empty.
I thought there might be some kind of limitation, but couldn't find anything so far except for the API rate limits which I don't exceed.
I also tried the graph API explorer and got the same result.
The problem was not solved but I found something I hadn't seen before, it might help people confused like me.
in the endpoint documentation it is declared that this endpoint has a 10k recent posts limitation, therefor we cannot get any more of our posts.

Facebook graphapi page/feed returning items sorted by relevance instead of recent activity

Hi I am using the Facebook graph api tool and attempting to get the feed of a public page. I want to get most recent comments first. However the feed returns comments and replies sorted by "relevance", is there a "sort" I can apply or how do I change this to get recent comments and replies within my posts?
I do not own the page I am getting the feed from.
There's the order parameter for comments, which can have the following values:
chronological
reverse_chronological
See
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.5#ordering
As far as I know, the feed's posts will always be sorted by created_time, and there's no way to influence this via the Graph API requests.

Facebook Graph API: Get post/status attached photos

How can one get multiple attachments of a post/status in a group?
For example: A group status that some member wrote and added multiple photos to..
Currently I am using Graph api to get the group stream with group_id/feed and unable to see images attached to a single status - while accessing the feed from Facebook itself I can validate that there are few photos attached to the status.
Using FQL it is possible to get the attachments with the following query:
SELECT attachment FROM stream WHERE post_id = each_post_id
Considering I will have to send this request per post and that FQL will soon be gone I am searching for an alternative.
I was looking for a solution for this as well and actually just found it.
The Facebook Platform changelog says the following:
/v2.1/{post-id} will now return all photos attached to the post: In
previous versions of the API only the first photo was returned with a
post. This removes the need to use FQL to get all a post's photos.
With this knowledge I went to the Graph Api Explorer and found a post that had 2 attachments or more added to it.
After finding the post, and with that the post id, I tried the request Facebook told me to do:
/v2.1/{post_id}
This does NOT give you the desired result. The nice thing about the explorer is that you can search for fields you want to add to your request.
You want to add the attachments (plural) field. NOTE: It might be that the graph api explorer only shows the attachment (singular) field. This is NOT right.
So, to summarize:
Get the post id of the post containing the images.
Create a new request to the graph api that looks something like: /v2.1/{post_id}?fields=attachments
Then read the result to get your desired attachments.
I hope this helps you out as I have been struggling for a while as well.
KR
PS: This is tested with a user and not a group, but it should be basically the same.
PS2: This is just an explanation of how you get attachments of a single post. You can also add the attachments field to the /me/home egde to immediately get all attachments at every post like so:
me/home?fields=message,from,attachments
PS3: The permissions you need are
user_status
read_stream
user_photos
user_videos
Facebook is not very clear on this matter and it is very hard to figure things out like this. So I hope this will help everyone that is searching for this solution.
I answered for the same question here : /v2.1/{post-id} does not deliver photos
It seems it's a Facebook bug. My colleague opened an issue. Here's the link: https://developers.facebook.com/bugs/762280800482269/
You also can find some info here:
https://developers.facebook.com/bugs/790976317600139/
Hope it will help you.

Facebook post id returned using graph api and the posted Id on facebook are not same

I need to retrive the comments for the particular post on Facebook, so whenever i post sometext on facebook using graph api as mentioned below.
$result = $facebook->api($fid.'/feed/','post',$attachment);
It returns the post id in response($result).
When i login to facebook and hover on the "datetime" for that post, it shows me the different post id and not the returned one in my response, so i couldn't get the comments for that post id.
I use to get the comments using the code below.
$post_comments = $facebook->api('/'.$postid,array('access_token' =>'AAAAxxxxxx'));
Any Help would be Appreciated!
Thanks,
The Post ID returned by the API is in the form {user_id}_{post_id} so its slightly different than the one facebook shows. However, if you replace the _ with /posts/ you get the same URL as the one Facebook provides.
I ran into this behaviour myself some days ago – user used three different apps and thereby created three individual link-posts. The "x minutes ago"-link for each of them showed a different number of minutes, but clicking on any of them led to the same post, the first on that was made.
I suspect it has something to do with all three post being made from page tabs on the same fan page(?) – but i looks like a bug to me, because to any of his friends following the "x minutes ago"-link on one of the other two posts it surely must be a bit confusing to be taken to a different post detail page than the one the actually clicked on.