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.
Related
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.
I want to fetch metadata of any web-page using Facebook Open Graph Object Debugger.
We can get it from this URL: Open Graph Object Debugger
Example: Open Graph Object Debugger for Google
It will provide all the information related to that URL. Is there any way to get this information using API(in JSON format)?
Yes, via the API URL Object described here and in even more detail here. Note that you can issue a POST request to this URL to force a refresh. You can even get additional data such as how many times that link was shared on Facebook!
https://graph.facebook.com/v2.10/?fields=og_object&id=http%3A%2F%2Fwww.imdb.com%2Ftitle%2Ftt2015381%2F&access_token={YOUR_TOKEN}
I did experience inconsistencies, namely if the obejct does not exist the API will return nothing but if you query it a few seconds later it will be there. For this reason we could not rely on Facebook and simply fetched the page ourselves and parsed out the og:* tags.
It may be perfect if you don't care about misses and having to re-fetch or if you just want to programmatically clear the Facebook OG cache.
It's wise to post to it every time you create a new page to force the cache or sometimes the first person to paste the URL into Facebook won't get the link preview!
Yes you can use this https://urlmeta.org
Its usage is pretty simple. Just make a GET call and pass the URL to API endpoint: https://api.urlmeta.org and you are done.
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.)
I'm the author of Fazzle app on iPhone. What my app does is basically download user status updates and sort them in various orders (e.g. most liked, most commented).
I have been wondering if Facebook allow developers to get user's status updates since the day they joined Facebook, because when I launched the app I can only get user statuses from 2009. Today I just discovered that Facebook limits Graph API calls down to just since 2011.
I tried looking at documentations, asked around here, and contacted Facebook through their forum. However so far there is no word on this limitation in Graph API. Did I miss something? Is there any other way for me to get data for status updates earlier than 2011?
You can test it yourself here. Use this GET request:
https://graph.facebook.com/(your_user_id)/statuses?limit=99999
Scroll down and you'll find out that not everything's downloaded.
Is this because of conflict of interest with Facebook Timeline? If so, that sucks.
Logged as a bug here. Still hoping someone can point out my mistakes if there's any.
Absolutely you can get older posts from Graph API; there is no limit (at least not that I am aware of). Use the since and until parameters to page back through results, instead of offset:
https://graph.facebook.com/me/feed?access_token=[token]&until=1165474447
Documentation for Paging doesn't go very in-depth on since and until:
When querying connections, there are several useful parameters that enable you to filter and page through connection data:
limit, offset: https://graph.facebook.com/me/likes?limit=3`
until, since (a unix timestamp or any date accepted by strtotime):
https://graph.facebook.com/search?until=yesterday&q=orange
But basically, until is like saying "Give me posts up until this date", and since is similar, "Give me posts since this date". So you can scroll all the way back through a user's feed using a loop something like this:
// pseudocode
timestamp = now
do {
posts = graph.get(/me/feed?until=timestamp)
if posts.length == 0: break;
// process posts
timestamp = posts[0].created_time // first should be the oldest, in theory
} while (1)
Replace until with since and oldest created_time with the newest to go forwards in time, e.g. to grab any newer posts since the last time the user ran the app.
Facebook has since confirmed this as a bug. If you have followed Facebook's bug tracker ever, unfortunately that means there is very little if any chance they will actually fix this.
You will need to paginate. Limit is limited. Please read http://developers.facebook.com/blog/post/478/
I'm a little confused trying to adapt to the new facebook Graph API.
Whereas before I would have used events.get, I'm not entirely sure what to use now!
I can't seem to get a list of a group's events through fql, nor through the Graph API itself.
Any pointers? Should I keep using REST?
In the documentation under "Connections" it doesn't appear that you can get /events. Or for that matter /albums or anything useful...
http://developers.facebook.com/docs/reference/api/group
However, if you know that something is an event (which you could probably do because the link in the data has "eid" in it - I can't see a way beyond that) then you can call the event URL (http://developers.facebook.com/docs/reference/api/event) and get the details that way.