我正在使用大查询示例代码来处理大查询。使用大查询 api 读取数据集列表时出现以下错误。
代码是
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());
}
}
例外是
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
)
我不认为这是一个身份验证问题,因为我可以使用相同的代码通过 Google plus api 连接到 Google Plus 帐户。我还观察到 api 示例已经过时。
任何修复它的建议。