【发布时间】:2019-05-02 09:58:01
【问题描述】:
所以我有一个场景,当我打开 firebase 函数的 url - https://us-central1-geochatterthing.cloudfunctions.net/getWall
我收到以下错误:
{"error":{"status":"INVALID_ARGUMENT","message":"Bad Request"}}
另外,我在 Cloud Functions 中的 getWall 函数如下图所示。
下面是 api-http.js 文件的链接:
https://gist.github.com/shubham6996/53cea6696b6d565b7f1ffce53bdaabf4
更新问题:
使用以下代码从我的 React Native 应用程序调用此函数:
const wallFunc = firebase.functions().httpsCallable('getWall');
let result = await wallFunc({size: 15});
当我使用以下代码检查result 的输出时:
console.log("Show result = "+JSON.stringify(result, this.getCircularReplacer()));
getCircularReplacer = () => {
const seen = new WeakSet();
return (key, value) => {
if (typeof value === "object" && value !== null) {
if (seen.has(value)) {
return;
}
seen.add(value);
}
return value;
};
};
上面的代码在控制台中显示了下面的输出:
显示结果 = {"data":{"docs":[{"sort":[1530702073924],"id":"04dhcfzDZbNLZoekfhl3"}],"hits":1}}
这里的“id”:04dhcfzDZbNLZoekfhl3 是从 Firebase 数据库集合中获取的文档的 ID。但我希望能够从该集合中获取每个文档的数据,而不仅仅是一个文档。
另外,一开始我提到的错误 "status":"INVALID_ARGUMENT" ,我发现了这个错误的一些东西:
如果调用了客户端触发器,但请求错误 格式,例如不是 JSON、具有无效字段或缺少 数据字段,请求被 400 Bad Request 拒绝, INVALID_ARGUMENT 的错误代码。
来源:https://firebase.google.com/docs/functions/callable-reference
在我的应用程序中,当我使用
调用可调用函数时const wallFunc = firebase.functions().httpsCallable('getWall');
let result = await wallFunc({size: 15});
我确实在这里将大小作为参数传递,但我不知道我是否在这里遗漏了什么。
在api-http.js 文件中,在这个文件的第 36 行,它显示数据有 2 个对象大小和来自,而我只传递大小参数。
附: - 我在这里解释我的问题可能是错误的,因为我实际上是在重新设计这个应用程序。所以我对这里的正确方法感到困惑。
【问题讨论】:
标签: firebase google-cloud-firestore google-cloud-functions