Google Cloud Messaging, returning 401 Unauthorized

夙愿已清 提交于 2019-12-22 08:32:50

问题


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.

来源:https://stackoverflow.com/questions/28849508/google-cloud-messaging-returning-401-unauthorized

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!