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

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

问题描述


$ b $我只想知道是否有可能从Android发送一个HTTP请求到云端函数并发布一些值,然后获取这些值并将其输入到实时数据库中。 b

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

谢谢。
祝你有个愉快的一天。

解决方案




  1. 从Android调用云端功能



    这与从Android调用任何其他HTTP URL。请参阅
    通过Firebase从Android调用云端功能

  2. HTTP触发的云功能实际上只是一个Express处理程序。所以解析帖子和其他Express处理程序一样。 用于HTTP功能的Firebase文档包含一些示例以及指向其他文档的链接。
  3. 从云端函数发布到数据库

    全部函数样本回购中的示例包含Firebase Admin SDK。此SDK允许您从功能中访问许多Firebase功能,例如数据库。但也有一个在这个回购的例子


I just want to know that is it possible to send an HTTP Request from Android to cloud function and posts some values and then get these values and input it to real time database.

var functions = require('firebase-functions');

exports.testPost = functions.https.onRequest((req, res) => {
console.log(req.body);
});

Thanks. Have a nice day.

解决方案

I see three steps in here:

  1. Calling a Cloud Function from Android.

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

  2. Parsing parameters from the call in your Cloud Function

    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.

  3. Posting to the database from a Cloud Functions

    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天全站免登陆