简体   繁体   English

对话推送通知中的 Twilio“GCM/FCM 未授权错误:GCM/FCM API 密钥已撤销或无效”

[英]Twilio "GCM/FCM unauthorized error: GCM/FCM API key is revoked or invalid" in conversations push notifications

I have implemented a simple chat using Twilio conversations API.我已经使用 Twilio 对话 API 实现了一个简单的聊天。 I'm following the doc for web push notifications ( https://www.twilio.com/docs/conversations/javascript/push-notifications-web ) and it's not clear to me what "FCM SECRET" I need to include in my Twilio Credential.我正在关注网络推送通知的文档( https://www.twilio.com/docs/conversations/javascript/push-notifications-web ),我不清楚我需要在我的Twilio 凭证。 I have tried with my firebase app key pair (public and private) and also with firebase web API key, but in the Twilio logs I allways get a GCM/FCM unauthorized error: GCM/FCM API key is revoked or invalid error.我已经尝试使用我的 firebase 应用程序密钥对(公共和私有)以及 firebase Web API 密钥,但在 Twilio 日志中我总是收到GCM/FCM unauthorized error: GCM/FCM API key is revoked or invalid错误。

Update:更新:

My app code:我的应用程序代码:

import { initializeApp } from "https://www.gstatic.com/firebasejs/9.8.2/firebase-app.js";
import { getMessaging, getToken, onMessage } from "https://www.gstatic.com/firebasejs/9.8.2/firebase-messaging.js";

const firebaseConfig = {
    apiKey: "...",
    authDomain: "...",
    projectId: "...",
    storageBucket: "...",
    messagingSenderId: "...",
    appId: "..."
};

const firebase = initializeApp(firebaseConfig);
const messaging = getMessaging(firebase);

const serviceWorkerRegistration = await navigator
    .serviceWorker
    .register('/js/firebase/firebase-messaging-sw.js');

if (firebase && messaging) {

    // getting FCM token
    getToken(messaging, {
        vapidKey: '...',
        serviceWorkerRegistration: serviceWorkerRegistration,
    }).then(async (fcmToken) => {

        console.log('token', fcmToken)
        const conversationsClient = await getConversationsClient();

        conversationsClient.setPushRegistrationId('fcm', fcmToken);

        onMessage(messaging, payload => {
            console.log('Message received. ', payload);
            conversationsClient.handlePushNotification(payload);
        });

    }).catch((err) => {
        console.log('Error getting token', err);
    });

} else {
    // no Firebase library imported or Firebase library wasn't correctly initialized
}

The fcmToken is generated and successfuly registered in Twilio. fcmToken在 Twilio 中生成并成功注册。

The Binding is created In Twilio with my credential referenced:绑定是在 Twilio 中创建的,并引用了我的凭据:

在此处输入图像描述

I believe the FCM Secret should be the apiKey that you get when you register the web application and get the details like this:我相信 FCM Secret 应该是您在注册 Web 应用程序并获取如下详细信息时获得的apiKey

Firebase 设置过程的屏幕截图,显示了将 Firebase SDK 添加到应用程序的部分。 Firebase 配置中的第一个键是 apiKey。

You also need to ensure you are using that config when you initialize the Firebase SDK in your application.您还需要确保在应用程序中初始化 Firebase SDK 时使用该配置。

If you are using that config, then perhaps you can share the code that you are using in your app to initialize Firebase and request an fcmToken from the user.如果您正在使用该配置,那么也许您可以共享您在应用程序中使用的代码来初始化 Firebase 并从用户那里请求一个fcmToken

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Twilio Conversations 使用 Firebase Cloud Messaging 推送通知 - Twilio Conversations push notifications with Firebase Cloud Messaging 通过GCM在渐进式Web应用程序中推送通知 - Push notifications in Progressive web app through GCM FCM推送通知在本地有效,但在服务器上无效 - FCM Push notifications works locally but not on server 如果浏览器在后台,FCM 推送通知会到达两次 - FCM Push notifications arrive twice if the browser is in background 如何使用带有FCM的服务工作者进行推送通知 - How to use service worker with FCM for Push Notifications Expo 推送通知:“错误:无法在设备上获取 GCM 令牌。” - Expo Push Notifications: “Error: Couldn't get GCM token on device.” 如何链接GCM chrome推送通知和有效载荷数据? - How do you link GCM chrome push notifications and payload data? FCm 错误=在 reactjs 中的推送通知上缺少注册? - FCm error=MissingRegistration on push notification in reactjs? 如何在 nuxtjs / vuejs 上实现 Firebase(FCM) 推送通知 - How to implement Firebase(FCM) Push Notifications on nuxtjs / vuejs 通过 FCM 同时收到两条相同的消息作为推送通知 - Two identical messages are received at the same time as push notifications through FCM
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM