Google Cloud Messaging, returning 401 Unauthorized

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

The getAccounts () method did return a valid google account. GoogleAuthUtil.getToken (context, account name, scope) also returns a valid scope string. However, the response from the message at 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 that I used to create the client-side notification key

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

And regarding the mail request, I 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 enable the authorization key to generate the notification key, but it did not work.

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

I wonder if this is a known issue, or does anyone have an idea? Thank you And I really appreciate your help.

I searched the forums as well as on stackoverflow, but did not find the answer.

+4
source share

Source: https://habr.com/ru/post/1204209/


All Articles