【发布时间】:2020-01-22 21:31:55
【问题描述】:
我是 Cloud Functions 的新手。
我有一个 Android 应用,它通过可调用客户端调用 Cloud Function,Cloud Function(node.js/typescript) 调用 Firestore 来读取数据。
云功能代码:
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp({credential : admin.credential.applicationDefault()});
exports.queryForData = functions.https.onCall((dats, context) => {
admin.firestore().collection('mydocument').get()
.then(snapshot => {
snapshot.forEach( e => {
if(e.exists)
{
console.log("docs="+e.ref.path);
return {"data":e.data()};
}
else{
console.log("No docs!!!!!")
return {"data":"empty"}
}
})
})
.catch(error => {
console.log("error occurred"+error);
return {error:error};
});
});
当我的 Android 应用调用此函数时,我收到一条被 catch 块显示的错误消息:ERROR: Could not load the default credential 并要求检查 Google Cloud Service Key 设置 URL,并且我已设置环境变量 GOOGLE_APPLICATION_CREDENTIALS 指向下载的 JSON 文件。
我试过initializeApp没有参数,有applicationDefault和functions.config().firebase的凭证
我已经放置了控制台日志来查看函数是否被调用并接收到 HTTP 调用,是的,它被调用了。但似乎问题出在我尝试获取收藏时。
Firestore 规则允许经过身份验证的用户读取文档。
我已经浏览了视频教程和之前在这里提出的问题,但似乎没有一个可以解决我的问题。
非常感谢任何帮助。
【问题讨论】:
标签: android node.js firebase google-cloud-firestore google-cloud-functions