0

I am trying to receive realtime updates from Facebook using their Realtime Updates API. I am just trying to get updates of the user's feed. I am using PHP to do all of this. I have it setup and verified, but I cannot access the response when they send it to my callback url. Is there a way to retrieve the json that is being sent to my callback url?

1 Answers1

1

From the docs:

The request will have content type of application/json and the body will comprise a JSON-encoded string containing one or more changes.

This means you can not access it in PHP using the “normal” way of accessing values in $_POST, because this request is not of the format form/urlencoded – it does not contain name=value pairs, but instead is in itself just a JSON-encoded string.

You should be able to read this data using the php://input stream wrapper – for example by simply using a line like

$inputdata = file_get_contents('php://input');

– and then you just use json_decode on the contents of this variable.

CBroe
  • 91,630
  • 14
  • 92
  • 150
  • I have one more question if you do not mind, how do I parse the json received from facebook realtime updates? I am currently using this code, and it is outputting nothing. Any thoughts??? if (isset($_POST)) { $inputdata = file_get_contents('php://input'); $obj = json_decode($inputdata); echo $obj["entry"][0]["uid"]; } – user1697872 Nov 26 '12 at 22:05
  • As I said, $_POST will not be populated … – CBroe Nov 26 '12 at 23:14