2

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.

Community
  • 1
  • 1
Mr. Blonde
  • 711
  • 2
  • 12
  • 27
  • it means your server API key or Token of your user – Divyesh Patel Dec 22 '16 at 08:09
  • @Divyesh I use my server API key to authenticate the request, so I can't imagine I have to use that also to target apps, right? – Mr. Blonde Dec 22 '16 at 08:10
  • how you send push? console or php? – Divyesh Patel Dec 22 '16 at 08:12
  • @Divyesh I use my ASP webserver to send a http-request. I create a JSON message object and send it. The response to my request is pasted into the question. – Mr. Blonde Dec 22 '16 at 08:13
  • 1
    make sure your API key is correct in ASP server, and FCM recently change API ley to TOken so try t – Divyesh Patel Dec 22 '16 at 08:15
  • @Divyesh It seems you are right. Now I get this response: {"multicast_id":6490441799688371670,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1482394663981462%0000000000000000"}]} StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent. – Mr. Blonde Dec 22 '16 at 08:26
  • @Divyesh But how do I target a specific app user or a group of users? – Mr. Blonde Dec 22 '16 at 08:27
  • 1
    @Mr.Blonde When sending to multiple users, you can make use of the `registration_ids` parameter, topics messaging, or device group messaging. See [here](http://stackoverflow.com/a/39547590/4625829). – AL. Dec 22 '16 at 08:48

2 Answers2

2

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.

AL.
  • 36,815
  • 10
  • 142
  • 281
  • The sample code you posted I imagine is run on the device. So if I have need to notifiy specific users, each device needs to register their tokens in my webserver on first run, and then I can use the tokens for notifying - is that correct? Or would I be able to get the tokens directly from the Firebase server? – Mr. Blonde Dec 22 '16 at 08:51
  • 1
    @Mr.Blonde Yup. The registration ids (aka. registration tokens) are generated on the client app side. You would have to send the tokens towards your app server afterwards. – AL. Dec 22 '16 at 08:59
  • 1
    For anyone reading this question, I can confirm that the suggested approach with sending the token to the webserver and then using it as a registration_id, works. I do find it a bit confusing that there are several words for the same thing in the API. – Mr. Blonde Dec 22 '16 at 12:41
-1

You should use Api server_key .

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

chris
  • 699
  • 4
  • 12
  • 35
sohan shetty
  • 289
  • 1
  • 16
  • Using the server API key, will target all users of all apps in my project, is that correct? – Mr. Blonde Dec 22 '16 at 08:34
  • This doesn't really provide a solution to the question. How does *using* the Server Key help with the InvalidRegistration error? – AL. Dec 22 '16 at 08:42
  • @AL - it does remove the error. But I am not sure where the notification goes. I imagine all apps in the project, and I would like to target more specifically. – Mr. Blonde Dec 22 '16 at 08:54
  • @Mr.Blonde It does? How so? It would be helpful if sohan shetty would give additional details how this fixes the issue would be included. AFAIK, the Server Key is used for Authentication of the message, and having the `InvalidRegistrationError` doesn't really mix up with it. – AL. Dec 22 '16 at 08:56
  • 1
    Api server _key is to connect you device and local server with cloud and if you want to target specific device then you should use registration id where you will be getting from client side and sending to your local server – sohan shetty Dec 22 '16 at 09:16