繁体   English   中英

firestore函数错误:获取应用程序默认凭据时发生意外错误

[英]firestore functions Error: Unexpected error while acquiring application default credentials

我在做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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM