[英]Google Cloud HTTP function by webhook: Request body is missing data
Im integrating the Zoom API with my Firebase app, and to do so I'm relying on Zooms pre-made webhooks to run an HTTP function on my Firebase for various events like "meeting started" and "meeting ended".我将 Zoom API 与我的 Firebase 应用程序集成,为此我依靠 Zooms 预制网络钩子在我的 Firebase 上运行 HTTP 函数以处理各种事件,例如“会议开始”和“会议结束”。 Zoom API reference: https://marketplace.zoom.us/docs/guides/webhooks Zoom API 参考: https : //marketplace.zoom.us/docs/guides/webhooks
This is the Google Cloud function that the Zoom API is calling:这是 Zoom API 正在调用的 Google Cloud 函数:
exports.zoomTestA = functions.https.onCall((req, res) => {
console.log(req);
let data = req.body;
var xmlData = data.toString();
console.log(xmlData);
});
Here is the payload sent by Zoom:以下是 Zoom 发送的有效载荷:
{
"event": "meeting.ended",
"payload": {
"account_id": "LTf-KjgUTR2df-knT8BVEw",
"object": {
"duration": 0,
"start_time": "2019-05-07T14:02:51Z",
"timezone": "",
"topic": "Alexander Zoom Meeting",
"id": "864370042",
"type": 1,
"uuid": "2h/SWVrrQMu7fcbpLUly3g==",
"host_id": "Ty6ykNolSU2k1N4oc0NRcQ"
}
}
This causes this error to appear in my Google Cloud console:这会导致此错误出现在我的 Google Cloud 控制台中:
Request body is missing data. { event: 'meeting.ended',
payload:
{ account_id: 'LTf-KjgUTR2df-knT8BVEw',
object:
{ duration: 0,
start_time: '2019-04-30T14:23:44Z',
timezone: '',
topic: 'Alexander\'s Zoom Meeting',
id: '837578313',
type: 1,
uuid: 'WotbHO3RRpSviETStKEGYA==',
host_id: 'Ty6ykNolSU2k1N4oc0NRcQ' } } }
The request body that Zoom sends is not wrapped in in a "data: {}" tag as required by Google Cloud functions. Zoom 发送的请求正文未按照 Google Cloud 函数的要求封装在“data: {}”标记中。 I've found solutions to this problem if you can control the payload here: Dart json.encode is not encoding as needed by Firebase Function .如果您可以在此处控制有效负载,我已经找到了解决此问题的方法: Dart json.encode is not encoding as needed by Firebase Function 。
My problem is that I am unable to alter the request that the Zoom API sends.我的问题是我无法更改 Zoom API 发送的请求。 Is there any way I can still accept the request in my Google Cloud function?有什么方法可以在我的 Google Cloud 功能中接受请求? Or is there any way to alter the format of the request sent by Zoom?或者有什么办法可以改变Zoom发送的请求格式? I'm unable to find references for either.我无法找到两者的参考。
One potential solution would be to set up another server that receives the request by Zoom, format it to Google Cloud functions specifications, and then pass it on to my Google Cloud function.一种可能的解决方案是设置另一台服务器来接收 Zoom 的请求,将其格式化为 Google Cloud 函数规范,然后将其传递给我的 Google Cloud 函数。 I would however like to avoid stepping out of the Google Cloud eco-system.但是,我想避免退出 Google Cloud 生态系统。
Is this problem solvable on the Google Cloud platform?这个问题在谷歌云平台上可以解决吗?
So I figured it out.所以我想通了。 In Firebase / Google Cloud functions you can either make HTTP-functions with在 Firebase / Google Cloud 函数中,您可以使用
functions.https.onCall((req, res) => { var data = req.body;
and和
functions.https.onRequest((req, res) => { var data = req.body;
The difference seems to be that onCall
is made for being used within the Firebase/ Google Cloud functions environment.不同之处似乎在于onCall
用于在 Firebase/Google Cloud 函数环境中使用。 However if you wan external functions you need to use onRequest
as this does not require specific formatting of the payload.但是,如果您需要外部函数,则需要使用onRequest
因为这不需要对有效负载进行特定格式设置。
Using onRequest
instead solved all my problems.改用onRequest
解决了我所有的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.