【发布时间】:2017-05-13 04:52:53
【问题描述】:
通过使用Not receiving webhook notification from drive, why? 此处描述的方法,我已经能够建立一个通道来接收来自 Google Drive 的推送通知。我收到通知,一切正常。我的问题是,当我收到推送通知时,我只收到以下信息:
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
根据this documentation,有一些包含请求正文的“更改”通知消息。不幸的是,我无法获得请求正文。
处理推送通知的脚本有以下逻辑:
$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 );
?>
我认为通过使用 $post = file_get_contents('php://input'); 我会捕获请求正文,但事实是它什么也没捕获。如果我理解正确,我应该会收到一个结构详细为here 的change 资源。我做错了什么还是我理解错了?感谢您提供任何见解,并提前致谢!
【问题讨论】:
-
我也有这个问题。你能解决这个问题吗?
-
我没有。我不知道在哪里可以得到这方面的指导。如果您能找到答案,请发布此问题的答案。
-
我也在这里问了一个问题。如果我找到解决方案,我会告诉你
-
我已经回答了这个问题。让我知道您是否有任何澄清
标签: php push-notification google-api google-drive-api google-api-php-client