问题
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>
Logcat shows this: 10-14 13:26:03.911: W/DefaultRequestDirector(22125): Authentication error: Unable to respond to any of these challenges: {}
I double checked the ip filtering, it does show:IPS Any IP allowed.
Wondering whether this is a known issue or anybody has any idea?
FYI I was able to get the id_token by GoogleAuthUtil.getToken. this is the http post format I followed: Http post body: { "operation": "add", "notification_key_name": "appUser-Chris", "registration_ids": ["4"] "id_token": "id_token" } headers: content-type: "application/json" Header : "project_id": Thanks!
来源:https://stackoverflow.com/questions/26242452/google-cloud-messaging-401-unauthorized-is-returned-when-creating-notification