Reputation: 67
I developing an app in which I send notifications using FCM REST API
.
But when I send the notification I always get the same error InvalidRegistration
.
When I googled the problem I knew that the problem is in the registration token format. so I wanna make sure if I'm sending the right token.
what I do is I authenticate users and the auth request returns.
{
"kind": "identitytoolkit#VerifyPasswordResponse",
"localId": "sQFWGMTlRvd8XgbxC9T6UyyKKNW2",
"email": "[email protected]",
"displayName": "",
"idToken": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjljYjU0Zjc4OTczNTU4NjU5ZTMxNGFkYzhjMTRkYzVmNjUyMTZmZmQifQ.eyJpc3MiOiJodHRwczovL3NlY3VyZXRva2VuLmdvb2dsZS5jb20vemVhbC1kZXYiLCJhdWQiOiJ6ZWFsLWRldiIsImF1dGhfdGltZSI6MTQ5ODI5ODUxNywidXNlcl9pZCI6InNRRldHTVRsUnZkOFhnYnhDOVQ2VXl5S0tOVzIiLCJzdWIiOiJzUUZXR01UbFJ2ZDhYZ2J4QzlUNlV5eUtLTlcyIiwiaWF0IjoxNDk4Mjk4NTE3LCJleHAiOjE0OTgzMDIxMTcsImVtYWlsIjoiMDEwMjY1MjUyMDBAemVhbC5jb20iLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsImZpcmViYXNlIjp7ImlkZW50aXRpZXMiOnsiZW1haWwiOlsiMDEwMjY1MjUyMDBAemVhbC5jb20iXX0sInNpZ25faW5fcHJvdmlkZXIiOiJwYXNzd29yZCJ9fQ.Uuuy7566wziSjp001WD_OwG2OdrsggwbuftCnsdpKTicVKArdayEVGq4-pBNsQOZKYNrhpTmiv86d_lbGeeuu9LNJX0xwjvslGA2EffdS1Vaf_OaBrwlp9rllTdXsIEp5wSpPUX_jSa2dck0lpU5bNPVAPjfw6_q4kmKkf6pMzjKLogGvJmtRJOuA5LMFIbJGrs57QIJfbDbghvG-etYAorgRIXwM1Xfg2eYD5s7sItwv0h9hitkH2R_Fy1yJuml51nbA6GT93YyE05QYowfmrymbfYOCYtOsfdkdL6iU0CLH8I0Cw7sQhGIx1iuQl1Wv5aNN2Z4QAiKERpt2VJ_Hw",
"registered": true,
"refreshToken": "ACXxpGEB6dkyDsmRVkaXrTshqAhQPZCSVC8kofhypeWDP473zIIOZQpAF_cMEQP6CaOB2PnyDiYX3cJdYAcG2Wcpyzcpij3s2TauyiaKqfYTy76EtvHDGZrW-FyHXc9fX1sRZWbW4uhslrEZ_tYy2axolmc7g3ZPfWAidqHjEjIzqS2moJTM5lXuvxBRlpZQcNXQFOGtr8E8",
"expiresIn": "3600"
}
so I use the idToken
to send the notification. Is that right or I'm doing something wrong.
Upvotes: 0
Views: 7020
Reputation: 19
I have also faced this issue..the problem was my device token column length in database table. when I change it to 255, it works.
Upvotes: 0
Reputation: 37798
The idToken
you're using doesn't seem to be a valid registration token for FCM, hence the InvalidRegistration
error.
You mentioned that that value (idToken
) is from a response after authentication, which is probably what it just is. From what I know about auth, it's usually just to identify the session and expires after a specific interval (expiresIn
).
For FCM, the needed value as a target is an actual token generated from the client side by calling getToken
. From the docs:
Retrieve the current registration token
When you need to retrieve the current token, call getToken. This method returns null when permission has not been granted. Otherwise, it returns a token or rejects the promise due to an error.
// Get Instance ID token. Initially this makes a network call, once retrieved // subsequent calls to getToken will return from cache. messaging.getToken() .then(function(currentToken) { if (currentToken) { sendTokenToServer(currentToken); updateUIForPushEnabled(currentToken); } else { // Show permission request. console.log('No Instance ID token available. Request permission to generate one.'); // Show permission UI. updateUIForPushPermissionRequired(); setTokenSentToServer(false); } }) .catch(function(err) { console.log('An error occurred while retrieving token. ', err); showToken('Error retrieving Instance ID token. ', err); setTokenSentToServer(false); }); }
The token generated usually comes in a format like:
<InstanceID>:<Actual token>
e.g.:
abcd1234:abcdefg123456
Double check if you're actually the correct method to generate the token.
Upvotes: 3