简体   繁体   中英

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. 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. 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.

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.

The Binding is created In Twilio with my credential referenced:

在此处输入图像描述

I believe the FCM Secret should be the apiKey that you get when you register the web application and get the details like this:

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

You also need to ensure you are using that config when you initialize the Firebase SDK in your application.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM