Cloud Functions for Firebase HTTP Request

一笑奈何 提交于 2019-12-30 13:56:22

问题


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

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

How can I accomplish this?


回答1:


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.



来源:https://stackoverflow.com/questions/44427085/cloud-functions-for-firebase-http-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!