2

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.

pushbit
  • 1,268
  • 9
  • 14
  • I've got the same problem, have you found a solution? – greywolf82 Dec 12 '15 at 10:49
  • No, I retried it on and off through the year, but always had the same problem. And after getting no response from DevRel, I've given up on it. – pushbit Dec 12 '15 at 16:11
  • Looks like notification_key_name needs to be the email of the user that gets your id_token, see [this answer](http://stackoverflow.com/a/34298106/3983628). – Andy Dec 16 '15 at 16:34

1 Answers1

0

You can try creating a new project with a new API key and see if you are still getting 401 error. And make sure you have 'Any IP allowed' not just IPv4 0.0.0.0/0.

so_jin_ee
  • 802
  • 6
  • 7
  • In this case I don't believe an API key is involved. My understanding is that the service would authenticate by checking if the `id_token` was generated for the referenced `project_id`. I have tried adding an `Authorization: key=API_KEY` header, as is required in the Generate a Notification Key on the Server method, but this did not help. I have also verified that my API key has "Any IP allowed". – pushbit Feb 11 '15 at 13:42