【问题标题】:FCM Go Adming SDK giving MismatchSenderIdFCM Go Adming SDK 提供 MismatchSenderId
【发布时间】:2018-03-15 06:41:54
【问题描述】:

我有一个包含两个组件的应用程序:一个使用 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 VAPID 密钥对,在将messaging.usePublicVapidKey('&lt;YOUR_PUBLIC_VAPID_KEY_HERE&gt;'); 行更改为messaging.usePublicVapidKey('&lt;MY_PUBLIC_VAPID_KEY_HERE&gt;'); 后使用FCM Web SDK sample code for messaging

此外,网络客户端应用托管在 Firebase 托管中。

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2018-06-26
      • 2016-10-18
      • 1970-01-01
      • 2017-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-21
      相关资源
      最近更新 更多