我已经在Google API中设置了一个与BigQuery一起使用的项目。我已经生成了客户端ID凭据,并且正在使用Android的BigQuery客户端。
GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(getApplicationContext(), Collections.singleton(BigqueryScopes.BIGQUERY));
...Display User Picker...
credential.setSelectedAccountName("[email protected]");
Bigquery bigQuery = new Bigquery.Builder(AndroidHttp.newCompatibleTransport(), GsonFactory.getDefaultInstance(), credential)
.setApplicationName("My-App/1.0").build()
...use bigQuery to run a job or do whatever...
我们可以成功连接到BigQuery,但只能连接到项目成员帐户,如https://console.developers.google.com/project/apps~my-project-name/permissions所示。使用其他帐户会导致BigQuery Client出现403拒绝访问JSON错误。
该应用程序将被部署到我们不知道其帐户提前的任何数量的用户。除非我缺少一些技巧,否则此工作流不支持该方法。
好像我们需要设置App Engine应用,使用GoogleAccountCredential.usingAudience以及将Web服务设置为BigQuery的传递一样。
任何想法或想法都将受到投票支持。
这可以通过使用通常用于服务器到服务器通信的服务帐户来完成。
按照https://developers.google.com/bigquery/docs/authorization#service-accounts-server上的说明进行操作。
GoogleCredential credential = new GoogleCredential.Builder().setTransport(TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId("[email protected]")
.setServiceAccountScopes(SCOPE)
.setServiceAccountPrivateKeyFromP12File(new File("my_file.p12"))
.build();
bigquery = new Bigquery.Builder(TRANSPORT, JSON_FACTORY, credential)
.setApplicationName("BigQuery-Service-Accounts/0.1")
.setHttpRequestInitializer(credential).build();
将p12文件保存到资产文件夹,并从Asset中的p12文件的InputStream生成物理File对象。
这样,您可以让您的Android应用程序充当BigQuery的非用户中心客户端。太棒了!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句