从android应用程序调用firebase函数后获取未定义

时间:2018-11-22 20:09:00

标签: android firebase google-cloud-functions

我有一个android应用,我想向Firebase云功能发送文本 我这样调用函数:

    private Task<String> test_function(String text) {
    // Create the arguments to the callable function.
    Map<String, Object> data = new HashMap<>();

    data.put("text", text); //Add the data you'd like to send to the server.


    return mFunctions
            .getHttpsCallable("test_function")
            .call(data)
            .continueWith(new Continuation<HttpsCallableResult, String>() {
                @Override
                public String then(@NonNull Task<HttpsCallableResult> task) throws Exception {
                    // This continuation runs on either success or failure, but if the task
                    // has failed then getResult() will throw an Exception which will be
                    // propagated down.
                    String result = (String) task.getResult().getData();
                    return result;
                }
            });
}

在我的node.js的index.js中,我尝试获取发送的文本

const functions = require('firebase-functions');
'use strict';

// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase- 
functions

var admin = require('firebase-admin');
var serviceAccount = require('./serviceAccountKey.json');

admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'https://weddingcalc-ab3d4.firebaseio.com'
});

var bodyParser = require('body-parser')
bodyParser.urlencoded();




exports.test_function = functions.https.onRequest((request, response) 
=> {
console.log('text: ' + request.query.text);


});

,我变得不确定: 我也尝试了request.body.text,但我仍然给未定义。 我在做什么错了?

picture of the functions log

0 个答案:

没有答案