问题
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.jsconst 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:
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
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.
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