firebase-admin-go: sender id does not match regisration token
I have an error
http error status: 403; reason: sender id does not match regisration token; code: mismatched-credential
everything made as said in documentation, i can send push notification from firebase web interface, but not from server.
my code is
func PushHandler(message <- chan Helpers.PushChannelMessage) {
log.Println("PushHandler INIT")
ctx := context.Background()
opt := option.WithCredentialsFile("XXXX.json")
config := &firebase.Config{ProjectID: "XXXX"}
app, err := firebase.NewApp(ctx, config, opt)
if err != nil {
log.Println(err)
return
}
client, err := app.Messaging(ctx)
for {
c:= <- message
fmt.Println("PushChan",c)
if err == nil {
message := &messaging.Message{
Data: map[string]string{
"score": "850",
"time": "2:45",
},
Token: c.Token,
}
response, err := client.SendDryRun(ctx, message)
if err != nil {
log.Println(err)
continue
}
fmt.Println("Successfully sent message:", response)
}else{
log.Println("error pushchan ->>", err)
}
}
}
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 15 (5 by maintainers)
yes, thanks! That fixes my problem too.
link: https://console.cloud.google.com/apis/api/fcm.googleapis.com/overview
We finally found the issue. Our Google Cloud project did not have enabled the Firebase Cloud Messaging API, just the Google Cloud Messaging.
After that initializing the GO Admin SDK without any credentials we are able to send push notifications. Also creating the credentials key JSON file in the Google Cloud console instead of in the Firebase console works.
Great job figuring this out @martinflorek. This is the full response sent by the FCM in this case:
The SDK ignores the message and only looks at the error code, which results in the confusing error. We can probably improve this behavior of the SDK. I’ll reopen the issue to keep track.
We have exactly the same problem. Interesting thing is that registering a FCM token into topic works, but sending a notification fails with the same
403error response.The only difference is that we are sending notification to a topic instead of to a token. And we are using the Firebase admin GO SDK on Google App Engine standard environment.