FCM Go Adming SDK提供了MismatchSenderId

I have an application that has two components: A server that uses FCM Go Adming SDK to send push notifications; and a web client that uses FCM web SDK to receive generate registration tokens and receive push notifications.

However, when I try to send a message from the server side; it gives me the following error despite the fact that both SDKs are registered on the same Firebase project:

http error status: 403; reason: sender id does not match regisration token; code: mismatched-credential

Server Component Details

I added the Firebase Admin SDK to my Server and initialized it with the service account credentials. The serviceAccountKey.json used for initilization looks like this:

        {
            "type": "service_account",
            "project_id": "myproject",
            "private_key_id": "<PRIVATE_KEY_ID>",
            "private_key": "<PRIVATE_KEY>",
            "client_email": "firebase-adminsdk-yg8ah@myproject.iam.gserviceaccount.com",
            "client_id": "<CLIENT_ID>",
            "auth_uri": "https://accounts.google.com/o/oauth2/auth",
            "token_uri": "https://accounts.google.com/o/oauth2/token",
            "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
            "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-yg8ah%40myproject.iam.gserviceaccount.com"
        }

And the server-side code for sending notifications looks like this:

    app, err := firebase.NewApp(context.Background(), nil, option.WithCredentialsFile("./resources/serviceAccountKey.json"))
    if err != nil {
        log.Fatalf("Failed to initialize the notifications server: %v
", err)
    }

    // Obtain a messaging.Client from the App.
    ctx := context.Background()
    client, err := app.Messaging(ctx)

    // The message payload.
    message := &messaging.Message{
        Data:         map[string]string{},
        Notification: &messaging.Notification{Title: "Title", Body: "Body"},
        Token:        "<Registration_Token>",
    }

    // Send a message to the device corresponding to the provided registration token.
    response, err := client.Send(ctx, message)
    if err != nil {
        log.Fatalf("Failed to send the push notification: %v
", err)
    }

Client Component Details

And for the web client, I created Web Push certificates VAPID key pairs used the FCM Web SDK sample code for messaging after changing the messaging.usePublicVapidKey('<YOUR_PUBLIC_VAPID_KEY_HERE>'); line to messaging.usePublicVapidKey('<MY_PUBLIC_VAPID_KEY_HERE>');

Also, the web client app is hosted in Firebase hosting.

1个回答



您可能尚未为项目启用FCM API。 参见 https://github.com/firebase/firebase-admin-go/issues / 116 获取更多背景信息。 该错误消息令人困惑,并将在以后的版本中修复以提供更多详细信息。</ p>
</ div>

展开原文

原文

You probably haven't enabled the FCM API for your project. See https://github.com/firebase/firebase-admin-go/issues/116 for more context. The error message is confusing, and will be fixed in a future release to provide more details.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐