我正在使用Android。
用户登录Firebase后,如何根据帐户在Firestore中检索用户信息?
我的功能在firebase的云功能中。 我的代码如下:
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");
}
});
答案 0 :(得分:1)
如果您需要使用firebase-firestore的帮助,可以使用内置助手。
转到Tools -> Firebase
并按照说明进行操作。
您可以使用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;
}
});
有关更多说明,Call functions from your app