Reputation: 23
Hi to everyone watching this post.
I have my app, and I want to know how to call my Firebase Cloud Functions in it. I've been reading from the Firebase guides but I am really struggling to understand how it works.
I have a function where I want to create parties, and I have some values to be inserted such as address, date, owner, etc.
If anyone who knows about this can help me I would be really grateful, I can provide any more information that you could need. Thanks!
Upvotes: 0
Views: 1186
Reputation: 83093
As Frank said, it is better when you ask a question on StackOveflow to include all the code you have already written.
However, from your comment, I understand you are referring to the code snippet that is in the documentation (copied/pasted below), and that you have problems with data.put
.
private Task<String> addMessage(String text) {
// Create the arguments to the callable function.
Map<String, Object> data = new HashMap<>();
data.put("text", text);
data.put("push", true);
return mFunctions
.getHttpsCallable("addMessage")
.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;
}
});
}
This Java code snippet shows that the data that is passed (sent) to the Callable Cloud Function is contained in an HashMap
, named data
.
You will find a lot of tutorials on the web on how to use an HashMap, but in a nutshell:
"A Java HashMap is a hash table based implementation of Java’s Map interface. A Map, as you might know, is a collection of key-value pairs. It maps keys to values." Source: https://www.callicoder.com/java-hashmap/
A way to add new key-value pairs to the HashMap is by using the put()
method. So this part of the code in the snippet is about adding data to the HashMap that will be sent to the CloudFunction.
And in the Cloud Function you will get this data as follows (as explained in the doc):
exports.addMessage = functions.https.onCall((data, context) => {
// ...
const text = data.text;
const push = data.push;
// ...
});
Upvotes: 2