How to successfully create a notification key on the client using GCM?

I follow the instructions below, but the response is always HTTP 401 unauthorized. I have confirmed that the identifier, registration identifier and project identifier (number) are valid. Unfortunately, the answer does not provide a detailed reason.

https://developer.android.com/google/gcm/notifications.html#gen-client

What is needed to receive an HTTP 200 response with key_ notification? I am wondering if the documentation is missing an important detail or if there is a known problem with this service. Otherwise, GCM and the Google auth token work fine for me.

Here is the edited online log. Does the request require any other JSON headers or fields that are not specified in the documentation?

---> HTTP POST https://android.googleapis.com/gcm/googlenotification project_id: {project-number} Content-Type: application/json; charset=UTF-8 {"id_token":"{long-auth-token}", "notification_key_name":"{unique-name}", "operation":"add", "registration_ids":["{reg-id}"]} <--- HTTP 401 https://android.googleapis.com/gcm/googlenotification 

Edit: I suspect that the id_token field id_token not used by the service. If I delete any other field, the response will be {"error":"Missing \"{field-name}\" field"} . But it does not return a similar response when id_token absent.

+2
source share
1 answer

You can try creating a new project using the new API key and see if you all get the 401 error. And make sure that you have "Any IP allowed" and not just IPv4 0.0.0.0/0.

0
source

Source: https://habr.com/ru/post/1204212/


All Articles