0

I subscribed to feed in the graph api webhook and I am receiving updates to my callback url as a charm, the issue is that I receive updates for each action that happens on the posts: likes, comments.. etc

I want to receive updates only if new post added to the wall, please advice ?

Do we have any fileds on the received json to my callback URL can I use to differentiate if this new post or a comment on a post ?

Liam
  • 6,009
  • 4
  • 39
  • 53

1 Answers1

1

You have to check the item field, there you'll find the item the update belongs to.

In your case ("new posts added to the wall") you have to filter for post in your code. Additionally you have to check the verb, because you get updates on edit and delete, too.

Norbert
  • 1,391
  • 1
  • 8
  • 18
  • Great!! thanks bro @Norbert , one more thing when I print out the request reader in my app engine servlet to see the json I received from the FB graph api , I note that I am always see the demo json , like below , why I dont receive the real json ? please advice {"entry": [{"changes": [{"field": "feed", "value": {"post_id": "44444444_444444444", "sender_name": "Test Page", "sender_id": "1067280970047460", "item": "status", "verb": "add", "published": 1, "created_time": 1502093917, "message": "Example post content."}}], "id": "0", "time": 1502093917}], "object": "page"} – wael mashal Aug 07 '17 at 08:22
  • I am retrieve the json in my servlet like this ' StringBuilder sb = new StringBuilder(); BufferedReader br = req.getReader(); String str; while( (str = br.readLine()) != null ){ sb.append(str); } log.info("RECEIVED NEW POST : " + sb.toString());' – wael mashal Aug 07 '17 at 11:46
  • I use this line, but this should not be the problem `final String body = req.getReader().lines().reduce("", (accumulator, actual) -> accumulator + actual);` Do you get only the demo json and don't receive anything other or do you print out the demo json and receive something different? – Norbert Aug 08 '17 at 07:08
  • Yes ,resp.setContentType("application/json"); String str; while( (str = br.readLine()) != null ){ sb.append(str); } log.info("RECEIVED NEW POST : " + sb.toString()); in my app engine console log I see always RECEIVED NEW POST : {"entry": [{"changes": [{"field": "feed", "value": {"post_id": "44444444_444444444", "sender_name": "Test Page", "sender_id": "1067280970047460", "item": "status", "verb": "add", "published": 1, "created_time": 1502094761, "message": "Example post content."}}], "id": "0", "time": 1502094762}], "object": "page"} – wael mashal Aug 08 '17 at 08:49
  • Perhaps you should put your code in a gist, so I can read it completely and in a better format :) https://gist.github.com/ – Norbert Aug 08 '17 at 09:16