4

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

Marcel Al Mutawa
  • 115
  • 2
  • 2
  • 7
  • Also make sure that you have activated the GCM API in the Developers Console. – Koh Mar 03 '15 at 17:11
  • I've got the same error, have you solved in someway? I'm trying to get the notification key in the client as well. – greywolf82 Dec 11 '15 at 19:00
  • 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:33
  • Possible duplicate of [Google Cloud Messaging (GCM) with local device groups on Android gives HTTP Error code 401](http://stackoverflow.com/questions/34098773/google-cloud-messaging-gcm-with-local-device-groups-on-android-gives-http-erro) – Andy Dec 16 '15 at 16:36

2 Answers2

0

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
petey
  • 16,914
  • 6
  • 65
  • 97
  • i changed the project_id to authorization and i entered MY_PROJECT_API_KEY as the value but I amgetting an error 400 OK. According to your statement you are trying to generate a notification key on the server however, i am trying to generate a Notification Key on the Client. Check this out - http://developer.android.com/google/gcm/notifications.html – Marcel Al Mutawa Mar 03 '15 at 19:49
0

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.

Koh
  • 1,570
  • 1
  • 8
  • 6
  • we got the id_token however when we pass it into – Marcel Al Mutawa Mar 05 '15 at 06:58
  • we got the id_token however when we pass it into JSON format to make a call to google server {"operation": "add", "notification_key_name":"a", "registration_ids":["**"] "id_token":"*" } I dont receive the notification key and I get an error of 401 OK – Marcel Al Mutawa Mar 05 '15 at 07:05