gpt4 book ai didi

node.js - 使用 firebase-admin 的 nodejs 中的错误方法 sendAll()

转载 作者:行者123 更新时间:2023-12-05 07:23:26 27 4
gpt4 key购买 nike

我使用 firebase-admin for nodejs(版本 7.3.0)发送推送通知。对于使用方法 sendAll 发送的 40k 不同消息,服务器经常收到此错误:

“通过“凭据”提供给 initializeApp() 的凭据实现属性无法获取有效的 Google OAuth2 访问 token 以下错误:“获取访问 token 时出错:发出请求时出错:套接字挂断。错误代码:ECONNRESET”。

有时效果很好,但并非始终如此。

var admin = require('firebase-admin');
serviceAccount = require('/path_json_adminsdk/yyyyyyyyyy.json');

var defaultApp = admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'https://api-project-yyyyyy'
});

var k = 42000;
var contorMessages = 0;
var messages = [];
for(var i=0;i <em><</em> k; i++){
//.......
contorMessages = contorMessages + 1;
var tmp = {
alert: body.alert,
payload: body.payload
};

//form the array to be sent
messages.push({
data: {"body": JSON.stringify(tmp)},
token: body.token
});

if(contorMessages == 100){
SEDispatcher.emit('sendMessageFirebaseMulticast',messages);
contorMessages = 0;
messages = [];
}

}

SEDispatcher.on('sendMessageFirebaseMulticast', function(messages){
var dryRun = true;

admin.messaging().sendAll(messages, dryRun)
.then(function(response) {
//console.log("response:",response);
//responses = response.responses;
//.......
})
.catch((error) => {
console.log(' +++ Error sending message:', error);
});

});

有时会出现的错误:

+++ Error sending message: { Error: 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: socket hang up. Error code: ECONNRESET". at FirebaseAppError.Error (native) at FirebaseAppError.FirebaseError [as constructor] (/opt/node/test/node_modules/firebase-admin/lib/utils/error.js:42:28) at FirebaseAppError.PrefixedFirebaseError [as constructor] (/opt/node/test/node_modules/firebase-admin/lib/utils/error.js:88:28) at new FirebaseAppError (/opt/node/test/node_modules/firebase-admin/lib/utils/error.js:122:28) at /opt/node/test/node_modules/firebase-admin/lib/firebase-app.js:121:23 at process._tickCallback (internal/process/next_tick.js:103:7) 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: socket hang up. Error code: ECONNRESET".' }, codePrefix: 'app' }

最佳答案

const messaging = getMessaging(defaultApp);

需要加载

关于node.js - 使用 firebase-admin 的 nodejs 中的错误方法 sendAll(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56054642/

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