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.

1 Answer 1

5
+50

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
3
  • 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. Jul 9, 2015 at 14:39
  • please check the following link: pcsupport.about.com/od/findbyerrormessage/a/401error.htm Jul 10, 2015 at 5: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]' Jul 10, 2015 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.