2015-11-21

I am using the Facebook graph API v2.5 to fetch /feed data from /group endpoints. I wish to locally cache the data inside my Realm database [a structured cache since the json data is structured in nature]. One of the issues I am facing is as follows.

Lets say 5 posts were made in total till 10 am.
When I start my app at 10 am, it loads P1, P2, P3, P4 and P5 for a group 'X'.

Lets say 2 posts were made between 10 am and 11 am. I am using the since parameter from Facebook graph API to load only those posts that were made between 10 am and 11 am. Lets say 2 posts were made P6 and P7.

Here is the problem. If I delete a post P5 from my app, the post is deleted from both Facebook and my cache.

If I delete the post P4 from my Facebook group 'X' it is not reflected in my app's local cache. How I can maintain synchronisation between my app's local cache and Facebook Graph API. Here are a few strategies I have in mind.

A) Load all posts everytime

This is the worst possible option in terms of bandwidth. Each time I load all 25 posts, if a post is there in the database but not present in the newly loaded feed, I delete it.

B) Delete with check

When a post is deleted from the app, there are 2 outcomes , the post is deleted successfully or not deleted. In the second case, there are 3 causes of failure

There was a problem with the internet while executing the delete request.

There was a problem with the FB servers while executing the delete request.

The object id does not exist on Facebook on scraping. This post covers how to check if an object exists or not on Graph API

C) Realm Time Graph API for Updates or WebHooks

This would be it but note that it talks about Page, User, Payment and Permission objects and not about Group objects. Even if it supports a Group object, it only indicates that something has changed, not what has changed which in my case would be a post getting deleted.

D) Let the person refresh manually

Well, I am not a fan of this approach but I don't see any better option.
My case requires the app to delete one or more posts. Any suggestions or options that I may have missed?

Show more