Where to find Reference_Ids for Firebase Cloud Mes

2019-01-29 05:24发布

问题:

After a lot of reading and Googling it seems I have made a complete setup for Google Cloud Messaging to send push-notifications. My missing link is the Reference_Ids that I must use to target apps. I have created a project and also added my apps to it.

When I send a push-request to GCM I get the following response:

{"multicast_id":7952352701122753715,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
    StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
    {
      X-Content-Type-Options: nosniff
      X-Frame-Options: SAMEORIGIN
      X-XSS-Protection: 1; mode=block
      Alt-Svc: quic=":443"; ma=2592000; v="35,34"
      Vary: Accept-Encoding
      Transfer-Encoding: chunked
      Accept-Ranges: none
      Cache-Control: max-age=0, private
      Date: Wed, 21 Dec 2016 16:12:43 GMT
      Server: GSE
      Content-Type: application/json; charset=UTF-8
      Expires: Wed, 21 Dec 2016 16:12:43 GMT
    }

And the error reads "InvalidRegistration".

So my questions are:

  • Where do I find my registration Ids?
  • And as a related follow-up question, where do I find Registration_Ids for everyone using an app or a specific group or user?

BTW: I found a related question, but it does not seem to have an answer to as where to find these Ids. StackOverflow post.

回答1:

InvalidRegistration means that the registration token (registration id) you used is invalid (doesn't exist, wrong format):

Check the format of the registration token you pass to the server. Make sure it matches the registration token the client app receives from registering with Firebase Notifications. Do not truncate or add additional characters.

Make sure that you are using the correct and corresponding registration token to the device you intend to send the message to. For testing, I would suggest to make use of the Firebase Console too, so that you can see if the error still occurs from there.

For Android, you can retrieve the registration token by calling:

FirebaseInstanceID.getToken()

You may then choose to store the token to your App Server.



回答2:

You should use Api server_key .

Go to firebase console -> click on your project -> click on gear icon -> project_setting -> cloud_messaging