Google Bigquery 401 unauthorized error using Service Account

google-bigquery

Solution

I would first make sure that your time is synced using ntpd, and that it is set to your correct time zone: http://www.ntp.org/

Problem

I ran into "401 Unauthorized" problem when I tried the bigquery snippet by Michael from this post on my computer. As suggested by ryguyrg, I synchronized my computer time (by clicking "update now") and the code worked. But the problem is, after a while, maybe several minutes, when I reran the code, it failed again with 401 Error. So I have to manually synch my computer time almost every time I want to run a big query request. I am pretty sure my computer is working well, and the time shouldn't differ by more than a couple of millisecond with respect to the server. So what exactly is causing the problem? Shall I try something to synch the time from code before the request or is there a better way around? 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) ```

Original source

Related problems