具有本地开发的云功能,并通过以下方式在本地启动它:
firebase模拟器:启动
云功能在这里:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp({
credential: admin.credential.applicationDefault(),
databaseURL:"https://test1-xxx.firebaseio.com",
});
我得到:
FirebaseAppError: Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "Error fetching access token: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal. Error code: ENOTFOUND".
at FirebaseAppError.FirebaseError [as constructor] (/Users/dgang/study/test/functions/node_modules/firebase-admin/lib/utils/error.js:42:28)
at FirebaseAppError.PrefixedFirebaseError [as constructor] (/Users/dgang/study/test/functions/node_modules/firebase-admin/lib/utils/error.js:88:28)
at new FirebaseAppError (/Users/dgang/study/test/functions/node_modules/firebase-admin/lib/utils/error.js:122:28)
at /Users/dgang/study/test/functions/node_modules/firebase-admin/lib/firebase-app.js:121:23
at processTicksAndRejections (internal/process/task_queues.js:89:5) { errorInfo: {
code: 'app/invalid-credential',
message: 'Credential implementation provided to initializeApp() via ' +
'the "credential" property failed to fetch a valid Google ' +
'OAuth2 access token with the following error: "Error ' +
'fetching access token: Error while making request: ' +
'getaddrinfo ENOTFOUND metadata.google.internal. Error ' +
'code: ENOTFOUND".' }, codePrefix: 'app' }
我根据需要定义了GOOGLE_APPLICATION_CREDENTIALS,但这无济于事。
我试图通过Google搜索该问题,但无济于事。
这里需要解决什么?
更新:
当我明确要求该服务帐户时,它会起作用:
var serviceAccount = require("service-account.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL:"https://test1-xxx.firebaseio.com",
});
但这是一个危险的选择