Invalid registration error on sending push notific

2020-07-26 04:17发布

问题:

I have written the client side code to receive the push notifications using service workers in my web app, Im running the app on localhost. How to invoke the notifications. I have included a manifest.json with sender_id.

Send a request from the command line for FCM to push a message, referred https://developers.google.com/web/fundamentals/getting-started/codelabs/push-notifications/ While executing curl command in terminal, I get the invalid registration error.

{"multicast_id":xxxxxxxxx,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}

I have verified server key and endpoint subscription ID, they are correct. But what is the issue ?

I have hosted my app using chrome web server, but how can I sendpush notification?

I have created a sample project Sample-App, I have hosted it on chrome webserver http://127.0.0.1:8888, and in firebase I have created project with Sample-App name which will generate API server key and gcm_sender_id.

I have also checked by hosting my code on github with https url, still the same issue

回答1:

I have been struggling with this issue past two weeks. Finally it works now. Issue is that, in regId I'm getting ... in between. That was throwing the invalid registration error. regid in console is trimming the content to ... in middle. So just before console.log you can check for reg id, it shows the complete id that you can use from curl command. It works as expected. Push notification pops up.