Firebase云功能:“状态":"INVALID_ARGUMENT"; [英] Firebase Cloud Functions: "status":"INVALID_ARGUMENT"
问题描述
我正在本地测试Firebase Cloud Function.当我按照此处所述使用本地URL http://localhost:5001/projectName/us-central1/functionName
调用此函数时:
I am locally testing a Firebase Cloud Function. When I call this function using the local URL http://localhost:5001/projectName/us-central1/functionName
as described here:
exports.createSession = functions.https.onRequest((_req, res) => {
res.status(200).send('TESTING');
});
该函数有效并返回字符串.
the function works and it returns the string.
但是,当我调用此函数时:
However, when I call this function:
exports.createSession = functions.https.onCall((data, context) => {
return 'TESTING';
});
它引发错误:{"error":{"message":"Bad Request","status":"INVALID_ARGUMENT"}}
我想使用后一个功能,因为我想访问context.auth
对象以检查用户Firebase身份验证.
I'd like to use the latter function because I want to access the context.auth
object to check for user Firebase authentication.
我正在使用Firebase CLI v8.4和Node v10.20.
I'm using Firebase CLI v8.4 and Node v10.20.
第二个功能使我无法正常工作吗?我不需要使用任何参数来调用它.
What am I missing from the second function to get it working? I am not calling it with any arguments as I do not need to.
推荐答案
答案是,您不能以与onRequest
方法相同的方式调用.onCall
方法,必须从SDK.如果缺少data
参数,则会引发错误:
The answer is that you can't call the .onCall
method in the same way as you can the onRequest
method, you have to call it from the SDK. If the data
argument is missing it will throw an error:
如果调用了客户端触发器,但是请求的格式错误,例如不是JSON,字段无效或缺少数据字段,则该请求将被400 Bad Request拒绝,错误代码为INVALID_ARGUMENT
If the client trigger is invoked, but the request is in the wrong format, such as not being JSON, having invalid fields, or missing the data field, the request is rejected with 400 Bad Request, with an error code of INVALID_ARGUMENT.
因此,即使您不需要使用该参数,也必须使用一个参数来调用它.
So you have to call it with an argument even if you don't need to use the argument for anything.
这篇关于Firebase云功能:“状态":"INVALID_ARGUMENT";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!