node.js - 用于身份验证的凭据没有权限
问题描述
我正在尝试使用 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 相同。还有什么我想念的吗?
解决方案
推荐阅读
- javascript - “display.style”在 JavaScript 中做了什么?
- angular - 在构造函数中测试 rxjs 管道运算符
- r - 一旦放入数据框中,日期就会神秘地转换为数字数据
- flutter - Flutter 像画布一样渲染到屏幕上。我如何实现这种布局?
- python - Flask_mail 连接被拒绝
- android - 二进制 XML 文件错误膨胀 RecyclerView
- android - 从设备上卸载我的应用程序使我无法再从 Android Studio 运行它
- javascript - 如何在打字稿中将这些对象转换为数组
- testing - Kotlin 测试类应该是内部的吗?
- spreadsheet - 如何在 Google 电子表格中永久隐藏可旋转的编辑器框?