0

I am using Big query sample code to work with big query. I am getting the following error while reading dataset list using the big query api.

The code is

Bigquery bigquery = Bigquery.builder(httpTransport, jsonFactory)
        .setHttpRequestInitializer(requestInitializer)
        .setJsonHttpRequestInitializer(new JsonHttpRequestInitializer() {
          public void initialize(JsonHttpRequest request) {
            BigqueryRequest bigqueryRequest = (BigqueryRequest) request;
            bigqueryRequest.setPrettyPrint(true);
          }
        }).build();


        Datasets.List datasetRequest = bigquery.datasets().list(PROJECT_ID);
        DatasetList datasetList = datasetRequest.execute();
        if (datasetList.getDatasets() != null) {
          java.util.List datasets = datasetList.getDatasets();
          for (Object  dataset : datasets) {
            System.out.format("%s\n", ((com.google.api.services.bigquery.model.DatasetList.Datasets)dataset).getDatasetReference().getDatasetId());
          }
        }

The exception is

Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
{
  "code" : 401,
  "errors" : [ {
    "domain" : "global",
    "location" : "Authorization",
    "locationType" : "header",
    "message" : "User is not a trusted tester",
    "reason" : "authError"
  } ],
  "message" : "User is not a trusted tester"
}
    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$Datasets$List.execute(Bigquery.java:964)
    at ShortSample.main(ShortSample.java:74

)

I don't see this as an authentication issue as I could use the same code to connect to Google Plus account via Google plus api. I also observed that api examples are stale.

Any Suggestions to fix it.

sudmong
  • 2,036
  • 13
  • 12

2 Answers2

0

I suspect you're using an older version of the BigQuery Java client library that is based on a prerelease version of the API (v2beta1). If that's the case, try upgrading to the latest version of the client library here:

http://mavenrepo.google-api-java-client.googlecode.com/hg/com/google/apis/google-api-services-bigquery/v2-rev5-1.5.0-beta/

We'll make sure the links on the API client library page are updated, too!

Jeremy Condit
  • 6,766
  • 1
  • 28
  • 30
  • Oh Yes.. API version was the issue. I was using v2beta1-rev3. Yes keeping API client library page in sync will help. – sudmong May 15 '12 at 02:24
0

I have encountered a similar problem and jcondit's solution works well for me (updating the jars). And for the authentication code, you may also take a look at here.

Community
  • 1
  • 1
Jack Guo
  • 137
  • 2
  • 9