通过代码启用Bigquery API

时间:2018-08-27 04:38:02

标签: google-api google-bigquery google-cloud-storage

我最近将Google SDK(客户端,oAuth等)从 1.22 升级到了 1.23 ,然后问题开始了。

在此document FLAG:-enable-cloud-apis 部分中,据说某些API(包括Big Query API)将默认启用,但具有创建项目时未启用这些API和服务。

当我用Google搜索它时,我发现了ServiceUsage库可用于该库。

我使用以下代码来启用API

HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = new JacksonFactory();

                GoogleCredential googleCredential =
                        GoogleCredential.fromStream(
                                GoogleCloud.class.getResourceAsStream(
                                        "path_to_cred.json"));

                ServiceUsage serviceUsage = new ServiceUsage.Builder(transport, jsonFactory, googleCredential)
                        .setHttpRequestInitializer(
                                request -> {
                                    googleCredential.initialize(request);


                                    int fiveMinutes = 5 * 60 * 1000;

                                    request.setConnectTimeout(fiveMinutes);
                                    request.setReadTimeout(fiveMinutes);
                                })
                        .setApplicationName("App_Name") 
                        .build();

                BatchEnableServicesRequest servicesRequest = new BatchEnableServicesRequest();
                servicesRequest.setServiceIds(ImmutableList.of("bigquery-json.googleapis.com", ...));

                ServiceUsage.Services.BatchEnable batchEnable =
                        serviceUsage.services().batchEnable("projects/project_id", servicesRequest);

但这不会启用API和服务。

有什么想法吗?谢谢

0 个答案:

没有答案