gpt4 book ai didi

javascript - firestore函数错误: Unexpected error while acquiring application default credentials

转载 作者:太空宇宙 更新时间:2023-11-04 03:21:18 24 4
gpt4 key购买 nike

我制作了 firestore 函数,但在日志中收到此错误

    import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'

var defaultApp = admin.initializeApp(functions.config().firebase)

const firestore = admin.firestore();
const firebase = admin.database();



module.exports.onUserStatusChange = functions.firestore.document('/status/{userId}').onUpdate((change,context) => {



const newValue = change.after.data();
console.log('new value',newValue);
console.log('change',change);
console.info('context',context)
admin.firestore().collection('status')
.where('state', '==', 'online')
.onSnapshot(function(snapshot) {
snapshot.docChanges.forEach(function(change) {
console.info('change->',change.type)
if (change.type === 'added') {
var msg = 'User ' + change.doc.id + ' is online.';
console.log(msg);
// ...
}
if (change.type === 'removed') {
var msg = 'User ' + change.doc.id + ' is offline.';
console.log('removed',msg);
// ...
}
});
});
return newValue;

});

我收到此错误是因为我在配置中定义了 firebase

    var defaultApp = admin.initializeApp(functions.config().firebase)

而不是 firestore,但在 firebase 的网络中我创建了 Firestore 数据库。所以我正在寻找一种方法将我的 Firestore 连接到此文件并使用 Firestore 数据库

最佳答案

更改此:

var defaultApp = admin.initializeApp(functions.config().firebase)

对此:

var defaultApp = admin.initializeApp();

更多信息在这里:

https://firebase.google.com/docs/functions/beta-v1-diff

关于javascript - firestore函数错误: Unexpected error while acquiring application default credentials,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49874927/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com