如何将参数传递给Firebase的云功能 [英] How to pass parameters to the cloud function of firebase

查看:56
本文介绍了如何将参数传递给Firebase的云功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Android.

I am using Android.

用户登录Firebase后,如何根据帐户在Firestore中检索用户信息?

After the user logs in to firebase, how can I retrieve the user information in the firestore according to the account?

我的功能在firebase的云功能中.我的代码如下:

My function is in the cloud function of firebase. My code as follows:

mFunctions.getHttpsCallable("getInfo").call()
            .continueWith(new Continuation<HttpsCallableResult, Object>() {
                @Override
                public String then(@NonNull Task<HttpsCallableResult> task) throws Exception {

                    Log.d("-----TEST-----", "BEGIN000");
                    Object result =  task.getResult().getData();
                    Log.d("-----TEST-----", "SUCCESS");
                    self_tel.setText((Integer) result);
                    return (String) result;
                }
            }).addOnCompleteListener(new OnCompleteListener<Object>() {
        @Override
        public void onComplete(@NonNull Task<Object> task) {
            if (!task.isSuccessful()) {
                Exception e = task.getException();
                if (e instanceof FirebaseFunctionsException) {
                    FirebaseFunctionsException ffe = (FirebaseFunctionsException) e;
                    FirebaseFunctionsException.Code code = ffe.getCode();
                    Object details = ffe.getDetails();
                }

                // [START_EXCLUDE]
                Log.w("test", "addMessage:onFailure", e);
                //showSnackbar("An error occurred.");
                return;
                // [END_EXCLUDE]
            }
            String result = (String) task.getResult();
            Log.d("-----TEST-----", "SUCCESS1");

        }
    });

推荐答案

如果您需要使用firebase-firestore的帮助,则可以使用内置助手.转到 Tools->Firebase ,然后按照说明进行操作.

If you want assistance using firebase-firestore you can use the inbuild assistant. Goto Tools -> Firebase and follow the instructions.

您可以使用 HashMap

// Create the arguments to the callable function.
Map<String, Object> data = new HashMap<>();
data.put("text", text);
data.put("push", true);

并使用 .call(data)

// Create the arguments to the callable function.
Map<String, Object> data = new HashMap<>();
data.put("text", text);
data.put("push", true);

return mFunctions
        .getHttpsCallable("getInfo")
        .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;
            }
        });

有关更多说明,从您的应用调用函数

这篇关于如何将参数传递给Firebase的云功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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