14

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.

Alex Timonin
  • 1,872
  • 18
  • 31

1 Answers1

5

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 AndroidManifest.xml
SID --- Choke_de_Code
  • 1,131
  • 1
  • 16
  • 41
  • 1
    Thanks for your response. The problem is: I do not send any of these requests manually. The library I mentioned in my question is supposed to do everything for me. And it does seem to work for others. – Alex Timonin Jul 09 '15 at 14:39
  • please check the following link: http://pcsupport.about.com/od/findbyerrormessage/a/401error.htm – SID --- Choke_de_Code Jul 10 '15 at 05:14
  • 1
    Thank you, I'm totally aware of what error 401 means. As I've already mentioned: I do not have access to code that is sending these requests. It's inside the library. The only thing I can control is project configuration at Google API. So I was hoping to get an answer like 'yeah, I faced the same issue, just go [here] and turn on [this feature]' – Alex Timonin Jul 10 '15 at 09:27