【发布时间】:2019-09-12 00:14:29
【问题描述】:
我正在关注tutorial 向网络应用程序添加推送通知,包括使用 VAPID 密钥调用firebase.messaging.usePublicVapidKey。但是,当我打电话给getToken 时,我收到以下错误:
请求缺少所需的身份验证凭据。预期的 OAuth 2 访问令牌、登录 cookie 或其他有效的身份验证凭据。见https://developers.google.com/identity/sign-in/web/devconsole-project
我已经在使用 VAPID 密钥,并且 Google 在教程中没有说过需要 Google OAuth 登录。我该如何解决这个问题?
var messaging = firebase.messaging();
messaging.usePublicVapidKey('redacted');
function obtenerToken() {
messaging.getToken().then(function (nuevoToken) {
if (nuevoToken) {
token = nuevoToken;
} else {
messaging.requestPermission().then(obtenerToken)
.catch(function (err) { console.log('La web no tiene permiso para recibir notificaciones ', err); });
}
}).catch(function (err) { console.log('Error al obtener token de Firebase ', err); });
}
obtenerToken();
【问题讨论】:
标签: javascript firebase firebase-cloud-messaging