Firebase HTTP 请求的云函数 [英] Cloud Functions for Firebase HTTP Request

本文介绍了Firebase HTTP 请求的云函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 Android 向云函数发送 HTTP 请求,发布一些值,然后将这些值输入到实时数据库中.

I want to send an HTTP Request from Android to a cloud function, post some values, then input these values into real time database.

const functions = require('firebase-functions');
exports.testPost = functions.https.onRequest((req, res) => {
  console.log(req.body);
});

我怎样才能做到这一点?

How can I accomplish this?

推荐答案

我在这里看到三个步骤:

I see three steps in here:

  1. 从 Android 调用云函数.

这与从 Android 调用任何其他 HTTP URL 相同.看通过 Firebase 从 Android 调用云函数

This is the same as calling any other HTTP URL from Android. See Calling a Cloud Function from Android through Firebase

从 Cloud Function 中的调用解析参数

HTTP 触发的云函数实际上只是一个 Express 处理程序.因此解析帖子的工作方式与其他 Express 处理程序相同.用于 HTTP 函数的 Firebase 文档 包含一些示例和指向其他文档的链接.

A HTTP triggered Cloud Function is really just an Express handler. So parsing the post works the same as for other Express handlers. The Firebase documentation for HTTP functions has some examples and links to other documentation.

从 Cloud Functions 发布到数据库

functions-samples repo 中的所有示例都包含 Firebase Admin SDK.此 SDK 允许您从函数中访问许多 Firebase 功能,例如数据库.但也有一个 此 repo 中的示例.

All the samples in the functions-samples repo include the Firebase Admin SDK. This SDK allows you to access many Firebase features, such as the database, from within your function. But there's also an example in this repo.

这篇关于Firebase HTTP 请求的云函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆