facebook api getting full posts with > 2 comments or > 4 likes - facebook

when I make the user/feed request on the Facebook Open Graph API, I get a feed object where posts with > 2 comments or > 4 likes don't reveal the detailed information for those specific comments.
I am using https://github.com/Thuzi/facebook-node-sdk to make requests but it is very similar to the 'request' NodeJS library.
I can get the full posts individually by making a separate request for that post's Open Graph ID, but this doesn't lend itself to fun code because requests are asynchronous and nesting more asynchronous calls within asynchronous calls doesn't lend itself to fun code.
Any way I can obtain the full posts?

Any way I can obtain the full posts?
You could use the (relatively) new Field Expansion feature, to set your own limit for likes and comments, like this:
/facebook/feed?fields=story,message,likes.limit(100),comments.limit(100)
If you expect (and need) more likes/comments, you might have to set the limits to higher values.
But warning, these queries can be quite time-consuming – I just tried the one shown using the Graph API Explorer, and it froze my browser for quite some time. (Although that’s partliy the Explorers fault, because it manipulates the data heavily before displaying it. Making the pure request against the API, https://graph.facebook.com/facebook/feed?fields=story,message,likes.limit(100),comments.limit(100)&access_token=…, shows to be quicker.)

Related

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 API get new comments to posts

I am using Facebook4j to access the Facebook API for a Page.
I can get a list of new posts for a Page, using
connection.getFeed()
and get the comments for a Post using:
post.getComments()
But I also want to be able to get new comments to the page posts (while ignoring comments that I've already fetched).
Any idea of how to do this, other than searching through the comments of every post all over again?
There is no way of doing it with the current Facebook4j API.
If you look at the list of the unsupported features on their page you will see:
Application APIs -Application - Facebook Developers
Ads APIs - Ads on the Graph API - Facebook Developers
Real-time Updates -Realtime Updates - Facebook Developers
Field Expansion - Field Expansion - Facebook Developers
Open Graph API - Open Graph - Facebook Developers
What you are looking for is real-time updates for the new comments.
You can take a look at this guide about subscribing to real-time updates.
If you'll look at the real-time updates link i provided above you will notice that real-time updates are limited to certain types of objects and a subset of their fields which are also listed there.
The valid types of objects for subscriptions available are the user and page Graph API object (with the feed field amongst others).
The real-time updates only indicate that a particular field has changed, they do not include the value of those fields. So this only makes apps more efficient, as they know exactly when a change has happened, and don't need to rely on continuous or even periodic Graph API requests when changes aren't happening.
You will know which field of the object (either user/page/permissions/payments) has changed, in your case the feed.
But other than that you will have to go through all the posts that you are interested in and the comments - though you could probably do it efficiently. For this you can probably keep your Facebook4j API code which gets the feed and recall it on upon updates. Or better yet upgrade the code to only track the changes you want and so on.
There is this example here (SO) on how to get facebook real time update in java. You'll get the point and probably build something better.
This answer suggests using Spring Social Facebook as it has a real-time update controller for handling real-time update callbacks from Facebook , whereas RestFB and Facebook4j can't do that.
To answer the question, if Facebook4j supports this, no, it does not.
This isn't done easily with the official graph API either, as comments use cursor based pagination; so filters like since and until will not work (they will work on things like feed though. (Source)
In order to do what you want, you would need to get all comments from now until the time you last got them. You can have comments returned ordered (most recent first, to oldest last) by using ?filter=stream
You can execute a raw fb request via fb4j for this:
// GET
Map<String, String> params = new HashMap<String, String>();
params.put("filter", "stream"); //add the ?filter=stream
//res will be the RAW response
RawAPIResponse res = facebook.callGetAPI("POST_ID/comments");
//you can get it as a JSONObj with:
JSONObject jsonObject = actual.asJSONObject();
OR, to do it without a raw request, you can use comment.getCreatedTime() to get the time for each comment, and then filter the old ones out.
Either way, you'll have to filter them yourself, as neither facebook4j nor the graph API support this natively.

How to get all user's likes using facebook's graph API

How can I query facebook's graph API to retrieve all user's likes (not only pages but also photos and others)?
For instance, how could I get all the pictures a user has liked? Using facebook's search bar you can find them easily by clicking on "photos has liked".
I wrote a script that scrapes the page content and does that but it's not very efficient.
I have recently come accross a similar problem, maybe this helps you solve it.
https://graph.facebook.com/v2.5/{page_id}/feed?fields=likes.limit(1).summary(true)&since={start_date}&until={end_date}&access_token={access_token}
This will give you a list of all posts that received likes during the specified time period. If you manage to write a code summing up the following JSON path you got your sum for "all user's likes":
data[0].likes.summary.total_count
Not entirely sure is this is exactly what you were searching for, hope it helps you though - and if not you, someone else.
As for likes you can also use the same way to extract Shares and Comments:
Shares
https://graph.facebook.com/v2.5/{page_id}/feed?fields=shares&since={start_date}&until={end_date}&access_token=
Comments
https://graph.facebook.com/v2.5/{page_id}/feed?fields=comments.limit(1).summary(true)&since={start_date}&until={end_date}&access_token=
Best regards
There isn't to my knowledge any way to get this from the API without grabbing every type of response from the API and then sorting through for likes. Facebook search bar uses an internal API different from the Graph API.

Final Checklist/Written Approval for Facebook Graph Use

i am using this endpoint
https://api.facebook.com/method/links.getStats?urls=
to collect the number of likes of specific urls. I want to display this information on a front end but do not want to make unnecessary API calls (there are over 25,000 posts). I would like to retrieve this information and store it so it can be retrieved from our database. On some pages, there will be over 10 of these accessible view a hover effect from a mouse. I would prefer to not have to load the page up with javascript targeted elements everywhere. It would be much easier to have the information stored and updated periodically. We will not be going over the impression limit or even coming close, but I would like to just make sure I'm not doing anything that will get me in trouble.
I would like permission to utilize this data to help increase pathways between our site and Facebook to allow people to share the page. I'm pretty sure we're doing everything correct but would just like to make sure and not step on anyone's toes.
I read through the checklist here
https://developers.facebook.com/docs/opengraph/submission-process/
however I don't know if what I'm doing would be considered an app....? Any advice would be appreciated.
Have a look at my answer here: How do I get the likes number from facebook for a given url?
You can also use FQL queries with IN lists to query multiple URLs at once. Please consider that a FQL statement can have a maximum length of 2048 characters.
select url, like_count from link_stat where url in ('URL1', 'URL2', ...)
The "cheklist" you linked is completely unneccessary, because you don't need to submit anything related to OpenGraph objects or actions. You can even use the functionality without using an Access Token, because the link_stat table is public (https://developers.facebook.com/docs/reference/fql/link_stat/)

Graph API's search returning considerately less public posts than Facebook's user facing search?

I'm developing an application based on facebook's data using the Graph API. Part of the functionality entails searching Facebook's public post, essentially in the same fashion that Facebook does on www.facebook.com/search:
http://www.facebook.com/search/results.php?q=thanksgiving&type=eposts&init=quick&tas=0.31611707084812224
However, when I issue the same search via the Graph API, the results return miss many of the posts shown in the standard user interface. Many of the most recent posts returned by the standard search are missing (replace the access_token to the one you have):
https://graph.facebook.com/search?q=thanksgiving&type=post&access_token=XXXX
Does anyone have an idea what can cause this and how I can work around it? I have customer questioning the quality of my application because of this difference.
Many thanks,
Boaz
That is because the Graph API uses pagination if it returns too many objects, if you take a look on the bottom of the response of the "Nike" search you will find this:
"paging": {
"previous": "https://graph.facebook.com/search?q=nike&type=post&access_token=XX&limit=25&since=1322257702&__previous=1",
"next": "https://graph.facebook.com/search?q=nike&type=post&access_token=XX&limit=25&until=1322246079"
}
Just make another request to the "next" url in order to fetch more results.