get notification key error 401 gcm https://android

2020-06-23 06:47发布

问题:

im trying to get notification key from google service im following the documentation from http://developer.android.com/google/gcm/notifications.html and im Generating a Notification Key on the Client but im having a problem with the post request getting error 401 OK

{
   "operation": "create",
   "notification_key_name": "vitee",
   "registration_ids": ["********"]
   "id_token": "**************************************************"
}

here is a snapshot of my request

![enter image description here][1]

https://lh5.googleusercontent.com/QmTDFWwjkyPtLFVVcTN4IYwkVhHU42wcUKPjpg_E8KSR3ALAXJ2Js-0K2gzlmmOEUXfrGe1TS8s=w1890-h820

回答1:

Your header for projectid is mislabeled and is using the project number instead of the API key as the value.

So,

  1. change project_id to Authorization as the name
  2. and as the value key=YOUR_PROJECT_API_KEY which may be found on the Credentials page:

Here's some help to find your api key via the Credentials page:

  1. https://console.developers.google.com/project?authuser=0
  2. Click the project you want (in case you have more than one)
  3. Click API & auth (if it isn't expanded already)
  4. Click Credentials (underneath API & auth)
  5. And then you will find your API key on this screen


回答2:

If you are creating a user notification on your client, you cannot use the "create" operation. Use "add" instead. As mentioned in the documentation, "add" creates the notification key if it doesn't exist.

In generating the id_token, make sure that you specify the client ID (not API key) in your scope object.