Tag: cloud messaging

推送通知会在Google云端函数中返回ECONNRESET

我在Firebase Cloud Functions中具有检索用户的设备组ID的function,以发送推送通知,并在发送推送通知之后进行。 如果这个函数只被调用一次,这个效果很好,但是如果我有一个用户数组,我也想发送一个推送通知,sendPushNotification函数返回错误: FAILED err= { RequestError: Error: read ECONNRESET at new RequestError (/user_code/node_modules/request-promise/node_modules/request-promise-core/lib/errors.js:14:15)每次尝试发送推送 从我所了解的ECONNRESET意味着连接在完成操作之前一端被closures了,可以有一些帮助/解释我为什么这样做: 这里是我的代码: function sendFollowNotification(snapshot) { const notificationMsg = getFollowNotificationMsg() //returns a string snapshot.forEach(function(singleUser, index) { const userId = singleUser.key; const userObject = singleUser.val(); console.log("will get device group") if (index + 1 == snapshot.numChildren()) { return getDeviceGroupNotificationKey(userId, "Discover new artists", notificationMsg, […]

通过Firebase生成推送通知

我试图从我的REST服务生成通知。 缺点是不发送,虽然fcm.googleapis.com/fcm/send反应是成功的。 这个我以两种方式做,首先由模块http: var http = require('http'); var options = { 'hostname': 'fcm.googleapis.com', 'path': '/fcm/send', 'method': 'POST', 'headers': { 'Authorization': 'key=<Key Server>', 'Content-Type': "application/json" } }; var data = { 'to':tokenPush, 'notification':notification }; var requestHttp = http.request(options, function(res){ res.setEncoding('utf8'); res.on('data', function (chunk) { console.log(chunk); }); }); requestHttp.on('error', function(e) { console.log('problem with request: ' + e.message); […]