5

我将 Zoom API 与我的 Firebase 应用程序集成在一起,为此我依靠 Zooms 预制的 webhook 在我的 Firebase 上运行 HTTP 函数,以处理“会议开始”和“会议结束”等各种事件。缩放 API 参考:https ://marketplace.zoom.us/docs/guides/webhooks

这是 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);
});

以下是 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"
    }
  }

这会导致此错误出现在我的 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' } } }

Zoom 发送的请求正文未按照 Google Cloud 函数的要求包装在“data: {}”标签中。如果您可以在此处控制有效负载,我已经找到了解决此问题的方法:Dart json.encode is not encoding as required by Firebase Function

我的问题是我无法更改 Zoom API 发送的请求。有什么方法我仍然可以在我的 Google Cloud 功能中接受请求?或者有什么办法可以改变 Zoom 发送的请求格式?我无法找到任何参考。

一种可能的解决方案是设置另一台服务器来接收 Zoom 的请求,将其格式化为 Google Cloud 功能规范,然后将其传递给我的 Google Cloud 功能。但是,我想避免退出 Google Cloud 生态系统。

这个问题在谷歌云平台上可以解决吗?

4

1 回答 1

22

所以我想通了。在 Firebase / Google Cloud 函数中,您可以使用

functions.https.onCall((req, res) => { var data = req.body;

functions.https.onRequest((req, res) => { var data = req.body;

不同之处似乎在于onCall在 Firebase/Google Cloud 功能环境中使用。但是,如果您需要使用外部函数,onRequest因为这不需要有效负载的特定格式。

相反,使用onRequest解决了我所有的问题。

于 2019-06-26T12:45:57.767 回答