4

I followed the example on https://developer.android.com/google/gcm/notifications.html#gen-client trying to create notification key from client.

getAccounts() method did return a valid google account. GoogleAuthUtil.getToken(context, accountname, scope) also returns a valid scope string. However the response from the post on https://android.googleapis.com/gcm/googlenotification is 401, and is an html page:

<HTML>
    <HEAD>
        <TITLE>Unauthorized</TITLE>
    </HEAD>
    <BODY BGCOLOR="#FFFFFF" TEXT="#000000">
        <H1>Unauthorized</H1>
        <H2>Error 401</H2>
    </BODY>
</HTML>

By the way here is the request code I used to generate the notification Key on the client Side

request:
{
   "operation": "add",
   "notification_key_name": "appUser-Chris",
   "registration_ids": ["4"]
   "id_token": "id_token"
}

And concerning the Post Request I have used this URL

 https://android.googleapis.com/gcm/googlenotification

Along with this header information

content-type: "application/json"
Header : "project_id": <projectID>

PS : I also tried to include the Authorization Key to generate the notification key but it didn't work .

Note : Keep in mind that I want to generate the Notif Key on the client side not on the server side.

Wondering whether this is a known issue or anybody has any idea? Thanks! And I would really Appreciate your help.

I have searched on forums as well as in stackoverflow , but I couldn't find any answer.

Sam Ben
  • 229
  • 1
  • 5
  • 11
  • Are you using the 12-digit project number in the Developers Console for your `project_id` header? – Koh Mar 04 '15 at 17:28
  • yes I m using the project id (12 digit). and My GCM Service is enabled as well . – Sam Ben Mar 04 '15 at 19:17
  • Can you double check your credentials? Make sure it is a Client ID (not an API key), and also of type "Web Application." – Koh Mar 04 '15 at 23:41
  • Client ID ?? where I should put my client ID ?? – Sam Ben Mar 05 '15 at 00:34
  • Yes client ID. Once you have it, place it in your scope like in the example: `final String scope = "audience:server:client_id:" + "1262xxx48712-9qs6n32447mcj9dirtnkyrejt82saa52.apps.googleusercontent.com";`. The string that ends in ".apps.googleusercontent.com" is the client ID. – Koh Mar 05 '15 at 00:57
  • Honestly I don't know what are you talking about . I don't need to use the client ID in my php Post Request . I have used the client ID to get the token ID , and it worked , but what I need right now is getting the notification key from gcm using PHP POST REQUEST. – Sam Ben Mar 05 '15 at 07:00
  • I've got the same problem, have you found a solution? – greywolf82 Dec 12 '15 at 10:46
  • @greywolf82 I think the error was from google server. because I tried it few days later and it did work without changing the code. – Sam Ben Dec 12 '15 at 18:24
  • 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

0 Answers0