首页 > 解决方案 > 用于身份验证的凭据没有权限

问题描述

我正在尝试使用 Firebase 云消息传递将 http 推送通知部署到实际设备上。如果是这样,我收到错误

“用于验证此 SDK 的凭据无权向与提供的注册令牌对应的设备发送消息。请确保凭据和注册令牌都属于同一个 Firebase 项目。”

我已经检查了前端和后端的凭据,它们都与我的火力库正确匹配。我在这里尝试了很多示例,但我错过了所有示例。我的 node.js 文件看起来像

const functions = require('firebase-functions');

const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

export GOOGLE_APPLICATION_CREDENTIALS = "/Users/myname/mylocation/myfile.json"



exports.sendPushNotifications = functions.https.onRequest((req, res) => {

 res.send("Attempting to send push notification")
 console.log("LOGGER --- Trying to send push message..");

 var uid = 'randomUIDString'

 var fcmToken = 'myToken'

 return admin.database().ref('/users/' + uid).once('value', snapshot => {

 var user = snapshot.val();

 console.log("username is " + user.name);

  var payload = {
  notification: {
  title: 'Push Notification Title',
  body: 'Test Notification Message'
  }
}

 admin.messaging().sendToDevice(fcmToken, payload)
 .then(function(response) {
 console.log('Succesfully sent message:', response);
 console.log(response.results[0].error);

})
.catch(function(error) {
  console.log('Error sending message', error);
    });

  })
})

用户名通过调用 uid 打印,但我无法访问 fcmToken。我检查了我的 info.plist 并列出了正确的项目。与苹果开发者和 appDelegate 相同。还有什么我想念的吗?

标签: node.jsfirebasefirebase-authenticationgoogle-cloud-functionsfirebase-cloud-messaging

解决方案


推荐阅读