I have been able to establish a channel to receive push notifications from Google Drive by using the method described here Not receiving webhook notification from drive, why?. I am receiving notifications and everything is working fine. My problem is that when I receive the push notifications, I am only getting this information:
Content-Length: 0
Accept: */*
Accept-Encoding: gzip,deflate,br
Connection: Keep-alive
Host: www.domain.com
User-Agent: APIs-Google; (+https://developers.google.com/webmasters/APIs-Google.html)
X-Goog-Channel-Expiration: Thu, 29 Dec 2016 00:00:00 GMT
X-Goog-Channel-Id: 01ecb23c-e718-8674-6ab3-623931741334
X-Goog-Message-Number: 2745870
X-Goog-Resource-Id: hw75x654x56jYhRNkfU5CFEXXXhtlj8
X-Goog-Resource-State: change
X-Goog-Resource-Uri: https://www.googleapis.com/drive/v3/changes?includeRemoved=true&pageSize=100&pageToken=658&restrictToMyDrive=false&spaces=drive&alt=json
According to this documentation, there are some "Change" notifications messages that include a request body. Unfortunately, I have not been able to get the request body.
The script that handles the push notifications has the following logic:
$oldcontent = file_get_contents('notifications.txt');
$newnotsfile = fopen("notifications.txt", "w");
$post = file_get_contents('php://input');
$requestBody = json_decode($post , TRUE); //convert JSON into array
$time = date("Y-M-d H:i:s", time());
fwrite($newnotsfile , "<br><br>---------------- │ Time: ".$time."<br><br>");
foreach (getallheaders() as $name => $value) {
fwrite($newnotsfile , $name.": ".$value."<br>");
}
fwrite($newnotsfile , $requestBody );
fwrite($newnotsfile , "<br><br>");
fwrite($newnotsfile , $oldcontent);
fclose($newnotsfile );
?>
I thought that by using $post = file_get_contents('php://input');
I would capture the request body but the truth is that it is capturing nothing. If I understand correct, I should receive a change resource with the structure detailed here. Is there something wrong that I'm doing or have I understood this wrong? I appreciate any insight that can be given and thanks in advance!