Trying to use Firebase for cross-platform mobile notifications. The client code to get a device token seems to work, as we can send notifications from the Firebase web console. But I cannot figure out how to send notifications from our server. We get the error: app instance has been unregistered; code: registration-token-not-registered; details: Requested entity was not found
when calling messagingClient.Send
in the following Go code snippet:
ctx := r.Context()
opt := option.WithCredentialsFile("serviceAccountKey.json")
app, err := firebase.NewApp(context.Background(), nil, opt)
if err != nil {
return err
}
// Obtain a messaging.Client from the App.
messagingClient, err := app.Messaging(ctx)
if err != nil {
return err
}
// See documentation on defining a message payload.
message := &messaging.Message{
Notification: &messaging.Notification{
Title: "Notification title",
Body: "Notification body",
},
Token: myDeviceToken,
}
// Send a message to the device corresponding to the provided
// registration token.
response, err := messagingClient.Send(ctx, message)
if err != nil {
return err
}
The credentials file that we're using is from the Firebase console, under Settings, Service Accounts, Firebase Admin SDK.
According to the documentation for FCM error codes, registration-token-not-registered means:
The provided registration token is not registered. A previously valid registration token can be unregistered for a variety of reasons, including:
- The client app unregistered itself from FCM.
- The client app was automatically unregistered. This can happen if the user uninstalls the application or, on iOS, if the APNS Feedback Service reported the APNS token as invalid.
- The registration token expired. For example, Google might decide to refresh registration tokens or the APNS token may have expired for iOS devices.
- The client app was updated, but the new version is not configured to receive messages.
For all these cases, remove this registration token and stop using it to send messages.
Given that there are several possibilities here, it's not really possible for us to say which one it is. If you need assistance troubleshooting with FCM, please contact Firebase support directly with exact steps anyone can take to reproduce the issue.