FCM Go Adming SDK提供MismatchSenderId

时间:2018-03-15 06:41:55

标签: firebase go push-notification firebase-cloud-messaging firebase-admin

我的应用程序有两个组件:使用FCM Go Adming SDK发送推送通知的服务器;以及使用FCM Web SDK接收生成注册令牌并接收推送通知的Web客户端。

然而,当我尝试从服务器端发送消息时;尽管两个SDK都在同一个Firebase项目中注册,但它给出了以下错误:

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

服务器组件详细信息

我将Firebase Admin SDK添加到我的服务器并使用服务帐户凭据进行初始化。用于启动的serviceAccountKey.json如下所示:

        {
            "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"
        }

用于发送通知的服务器端代码如下所示:

    app, err := firebase.NewApp(context.Background(), nil, option.WithCredentialsFile("./resources/serviceAccountKey.json"))
    if err != nil {
        log.Fatalf("Failed to initialize the notifications server: %v\n", 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\n", err)
    }

客户端组件详细信息

对于网络客户端,我在将Web Push certificates行更改为messaging.usePublicVapidKey('<YOUR_PUBLIC_VAPID_KEY_HERE>');之后创建了使用FCM Web SDK sample code for messagingmessaging.usePublicVapidKey('<MY_PUBLIC_VAPID_KEY_HERE>');个VAPID密钥对

此外,Web客户端应用程序托管在Firebase托管中。

1 个答案:

答案 0 :(得分:1)

您可能尚未为项目启用FCM API。有关更多上下文,请参阅https://github.com/firebase/firebase-admin-go/issues/116。错误消息令人困惑,将在以后的版本中修复以提供更多详细信息。