I'm following the below instructions, but the response is always HTTP 401 Unauthorized. I have verified that the ID token, registration ID, and project ID (number) are all valid. Unfortunately the response does not provide a detailed reason.
https://developer.android.com/google/gcm/notifications.html#gen-client
What is necessary to receive an HTTP 200 response with the notification_key? I'm wondering if the documentation is missing an important detail or if there is a known issue with the service. Otherwise GCM and the Google auth token are working fine for me.
Here is a redacted net log. Does the request require any other headers or JSON 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'm suspicious that the id_token
field is not being used by the service. If I remove any other field, the response is {"error":"Missing \"{field-name}\" field"}
. But it doesn't return a similar response when id_token
is missing.