I ran into the "401 Unauthorized" problem when I tried a fragment of Michael’s big square from this message on my computer. As suggested by ryguyrg, I synchronized my computer time (by clicking "upgrade now") and the code worked. But the problem is that after a while, maybe a few minutes, when I restart the code, it again does not have the 401 error. So, I have to manually synchronize the time of my computer almost every time I want to start a large query request.
I am sure my computer is working well and the time should not differ by more than a couple of milliseconds relative to the server. So what exactly is causing the problem? Should I try something to synchronize time with the code before the request, or is there a better way?
Below is the 401 error message for reference:
Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:159)
at com.google.api.client.googleapis.json.GoogleJsonResponseException.execute(GoogleJsonResponseException.java:187)
at com.google.api.client.googleapis.services.GoogleClient.executeUnparsed(GoogleClient.java:115)
at com.google.api.client.http.json.JsonHttpRequest.executeUnparsed(JsonHttpRequest.java:112)
at com.google.api.services.bigquery.Bigquery$Jobs$Insert.executeUnparsed(Bigquery.java:1418)
at com.google.api.services.bigquery.Bigquery$Jobs$Insert.execute(Bigquery.java:1442)
at BigQueryJavaServiceAccount.main(BigQueryJavaServiceAccount.java:83)
source
share