how to get the all the likes from a post in restFB - facebook-graph-api

i have been trying to get few information details that somehow always return as null. the one that is most needed for me is likes count (or even better, just all the likes. i want to know who liked the post).
my code is
FacebookClient fc = ~my facebook client in version 2.3~;
Post post = fc.fetchObject(anID, Post.class ;
System.out.println("Likes Count - "+ post.getLikes().getData().size());
im trying like so cause this way i get the number 25. so i got it , its limited to 25. how do i get all of the likes??
by the way , if ill just try post.getLikesCount() ill get nothing.
if anyone knows how to handle this situation he might also know how to get Attribution , Shares and FeedTargeting.
thanks for you attention!

To get all Likes of a Post you can request the <postid>/likes endpoint. You can iterate over the pages and the likes.
Perhaps there's a way to use the field expansion, but I'm not sure atm.

Related

How to get post views with the help of Facbook API Graf

I'm trying to get post statistics on Facebook. I need to get the number of likes, dislikes, veiws and comment. I have already found the way to get post information: https://graph.facebook.com/v11.0/{page_name}?fields=name,posts&access_token=_____
But when I'm trying to get likes and comments, I get nothing: https://graph.facebook.com/v11.0/{page_name}?fields=name,posts{reactions,comments}&access_token=
You are likely not getting any specific reactions and comments, because you lack the right to access those. (They contain user data, and user data is only available if the individual user gave your app permission.)
If you only need the overall count, then ask for the summary:
?fields=name,posts{reactions.summary(1),comments.summary(1)}

Get page insights and post insights in the same request

Hello i am trying to get page level insights and post level insights in the same request but cant seem to get the syntax correct.
page id /published_posts?fields=permalink_url,created_time,message,shares,reactions.limit(0).summary(1),comments.limit(0).summary(1),insights.metric(post_reactions_by_type_total,post_impressions_unique,page_posts_impressions_organic)&since=yesterday
This is my request for now but i wanna add page insights like page_fans and page_fans_city.
How can i do that?
You are using the published_posts endpoint there already, you can not go back “up” to the page object from there. You need to rewrite the whole thing so that you use the page id itself as the basic endpoint, and then request everything else via the fields parameter. The trick is to get the syntax and nesting right …
/page-id?fields=insights.metric(page_fans,page_fans_city),published_posts{…}
should work, inside the {…} you then put all the original fields you requested from the published_posts endpoint before, so
/page-id?fields=insights.metric(page_fans,page_fans_city),published_posts{permalink_url,
created_time,…,insights.metric(post_reactions_by_type_total,post_impressions_unique,
page_posts_impressions_organic)}
And &since=yesterday then just goes at the end again, after all that.
To have the since limitation still apply on the post level, it apparently needs to be added on that “field” again, syntax similar to .metric():
?fields=…,published_posts.since(yesterday){…}

how to get likes counts from a Facebook page using Graph Explorer 2.4

While this question has been asked a lot, I've still haven't find a way to do it.
I'm passing this to Graph Api Explorer
40796308305/?fields=feed{full_picture,created_time,message,likes}
this gives me the, Picture to every status, created time , message - user status and likes which gives me array of data and users that likes the status.
i'm trying to get count of those users and remember there were a field 'summary' but I don't see it in the JSON Results.
Am I missing something with 2.4 api version ?
any help will be appreciate.
You need to request the summary:
/40796308305/?fields=feed{full_picture,created_time,message,likes.summary(1)}
And if you are only interested in the total count, but not the individual users that liked, you might want to set the limit for likes to 0, so as not to request unnecessary data:
/40796308305/?fields=feed{full_picture,created_time,message,likes.limit(0).summary(1)}

Parameter not supported by web service

I want to validate an opinion with you.
I have to design a web service that searches into a database of restaurants affiliated to a discount program in a specific country around a given address.
The REST call to such a webservice will look like http://server/search?country=<countryCode>&language=<languageCode>&address=<address>&zipcode=<zipcode>
The problem is that some countries do not have zipcodes or do not have them in the entire country.
Now, what would you do if the user passes such a parameter for a country that does not have zipcodes, but he/she passes a valid address?
Return 400 Bad request.
Simply igonre the zipcode parameter and return results based on the valid address
Return an error message in a specific format (e.g. JSON) stating that zipcodes are not supported for that country
Some colleagues are also favoring the following option
4. Simply return no results. And state in the documentation that the zipcode parameter is not supported. Also we have to create a webservice method which returns what fields should be displayed in the user interface.
What option do you think is best and why?
Thanks!
Well the OpenStreetMap Nomination Server returns results even if you dont know the ZIP Code and you can look at the results anyway. What if the user doesnt know the zip code but wants to find hist object?
I would try to search for that specific object anyway, especially because you said that some countries have zip codes partially.
If you simply return nothing te user doesnt know what went wrong and he wont know what to do.
That would depend on the use case. How easy is it for a user of the API to trigger that case? Is it a severe error which the user really should know how to avoid? Or is it something that is not entirely clear, where a user may know (or think he knows) a zipcode where officially there shouldn't be one? Does it come down to trial and error for the user how to retrieve correct results from your API? Is it a bad enough error that the user needs to be informed about it and that he needs to handle this on his side?
If you place this restriction in your API, consider that it will have to be clearly documented when this case is triggered, every user of the API will have to read and understand that documentation, it needs to be clear how to avoid the problem, it needs to be possible for the user to avoid the problem and every user will have to correctly implement extra code on his side to avoid this problem. Is it possible for the user to easily know which areas have zipcodes and which don't?
I think the mantra of "be flexible in what you accept, strict in what you output" applies...

Graph API: Number of Comments for Posts Are Inconsistent Among Various API Calls

Hello Graph API experts,
When you call /[post_id , the result contains "comments" field which has "count" field that is supposed to have the total number of comments for this particular post.
Now, if you call /[post_id]/comments , you get the actual comment data, one by one.
The problem I am facing is that, when I compare the "comments.count" field's value and the number of all of the actual comment data returned, they are different.
What's even worse, if you then look at the same post on Facebook.com's Timeline where you can see the number of comments for that post (i.e. "view all * comments" link), this number is also different from the "comments.count" field value.
And this is not only happening to one post, but to many of them - I observe this tend to happen more to posts with more than 100 comments (I actually counted all the comments on Timeline, and it matched the number of the actual comment data returned from /[post_id]/comments API call).
Is this a normal API behaviour? Which number should I or would you trust if this is the way it is?
ok, when you looking some facebook comment counts on some timeline posts, you woulld see that count for ex. 16 comments, and when you try to count comments manually on the post you may see it's looking 15 comments, so where is it that missing comments ? is that a wrong count by facebook ? no not actually, it's because, some people changing profile privacies as like don't show my comments people who aren't my friends, or we haven't any mutual friends, etc. it's because you cannot get these privatized comments from graph api, but these comments aren't excluding in total count. So what's the solution, just be sure get all the data correctly what facebook provide you. And compare it, how many comments looking like missing, and show missing counts as private comments count in your application. I think is much better.
Welcome to the world of Facebook API programming. Yes, this is normal (but apparently not desired) API behavior. This is one of the inconsistencies we're faced with when programming around their API. CBroe is probably correct in his comment above, it is data inconsistencies between servers in their API cluster.
in addition to this there are problems with pagination, you can use the offset + limit parameters to say how much data you want and from where to take it, if you deal with number of posts, you can say offset=0 and limit=50 and it'll work, but then if you try offset=100 and limit=50 it might return empty data, but then try offset=100 and limit=100 and it'll return 100 posts.
the api is just buggy and full of inconsistencies which don't seem to have any way to solve them.
I think we got oversold on the opengraph, I don't think it's what facebook told us it would be and I'm starting to feel the burn from selling that to my boss and finding out that I perhaps can't deliver :(