Вот как мы аутентифицируем и вызываем FirestoreAdminClient.
import fs from 'fs';
import firebaseAdmin from 'firebase-admin';
const pathToServiceAccountKeyFile = '/path/to/service/account/key.json';
const serviceAccountKeyJSON = fs
.readFileSync(pathToServiceAccountKeyFile)
.toString();
const serviceAccountKeyObject = JSON.parse(serviceAccountKeyJSON);
firebaseAdmin.initializeApp({
credential: firebaseAdmin.credential.cert(serviceAccountKeyObject)
});
const adminClient = new firebaseAdmin.firestore.v1.FirestoreAdminClient({
keyFilename: pathToServiceAccountKeyFile
});
adminClient
.exportDocuments({
name: adminClient.databasePath('firebase-test-project-id', '(default)'),
outputUriPrefix: 'gs://firebase-test-project-backups'
})
.then(response => console.log(response));
Это выходные данные оператора console.log.
7 PERMISSION_DENIED: The caller does not have permission
at Object.callErrorFromStatus (node_modules/@grpc/grpc-js/build/src/call.js:30:26)
at Http2CallStream.call.on (node_modules/@grpc/grpc-js/build/src/client.js:96:33)
at process.nextTick (node_modules/@grpc/grpc-js/build/src/call-stream.js:75:22)
Здесь мы создали сервис ключ счета.
Ссылки:
https://googleapis.dev/nodejs/firestore/latest/index.html