dongyishe6689 2018-03-15 06:41
浏览 213

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条回答

  • dsfphczao23473056 2018-03-15 17:20
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面