Home » Android » android – Google Play API returning error 401

android – Google Play API returning error 401

Posted by: admin May 14, 2020 Leave a comment


I’m using gradle-play-publisher library to upload my app to Google Play, but I get error 401 Unauthorized when executing the publishing task.
My dev account at Google Play and service account at Dev Console are set up. Play API is enabled.

As I see from build logs, the first request sent is:

POST https://accounts.google.com/o/oauth2/token

I get 200 OK and the following json:

  "access_token" : "< some value here>",
  "token_type" : "Bearer",
  "expires_in" : 3600

Then the next request is sent:

POST https://www.googleapis.com/androidpublisher/v2/applications/< my app's package name here>/edits

First of all, I noticed this header among others:

Authorization: <Not Logged>

And second, I get this error as a response

401 Unauthorized
WWW-Authenticate: Bearer realm="https://accounts.google.com/", error=invalid_token

Has anyone faced the same issue? Everything seems to be set up correctly, so I have no idea what went wrong. Thank you.

How to&Answers:

Your error means that

server responded with 401 (Unauthorized) status code but failed to provide a single auth challenge (WWW-Authenticate header) thus making it impossible for HttpClient to automatically recover from the authentication failure.

Check your HTTP POST request in you application which might expect
some short of credentials in the HTML form

I hope that you are already testing your rest API(url) by using POSTMAN google chrome extension.

Now,if your rest api works fine then consider about using that in your code, step by step try to figure out the following

  1. server implementation is wrong or client side implementation wrong or url
  2. parameters are wrong
  3. check for <uses-permission android:name="android.permission.INTERNET" /> in your