1
下面是我們用來獲取bigquery客戶端的工作代碼示例。我們想調整它,以便我們可以跨不同的項目進行查詢。例如,在project1上運行查詢,但將結果保存到project2中的表中。我所做的是獲取project2的身份驗證,但在查詢中提供了對project1中表的完整路徑引用,但它不適用於在寫入Bigquery時作業失敗。 accessDenied:訪問被拒絕。(job_id:job_queryToTable_c43f8d51-01a5-492c-b648-e15171bb65db_266866506361660)。我該怎麼辦?Bigquery:如何訪問Bigquery JAVA API中的另一個項目?
private void getBigQuery() {
if (mBigquery == null) {
HttpTransport transport = new NetHttpTransport();
List<String> lScope = new ArrayList<String>();
lScope.add(ConfigConstants.SCOPE);
GoogleCredential credential;
try {
credential = new GoogleCredential.Builder()
.setTransport(transport)
.setJsonFactory(ConfigConstants.JSON_FACTORY)
.setServiceAccountId(ConfigConstants.SERVICE_CLIENT_ID)
.setServiceAccountScopes(lScope)
.setServiceAccountPrivateKeyFromP12File(new File(ConfigConstants.KEY_FILE)).build();
mBigquery = new Bigquery.Builder(transport,
ConfigConstants.JSON_FACTORY, credential)
.setApplicationName("BigQuery-Service-Accounts/0.1")
.setHttpRequestInitializer(credential).build();
} catch (GeneralSecurityException e) {
//TODO e.printStackTrace();
} catch (IOException e) {
//TODO e.printStackTrace();
}
}
}
無效補助上來時,我試圖從表中獲取表信息在其他項目
Table table = mBigquery.tables().get(project2,dataset,tableId).execute();//mBigquery is with credential for project1 and get table is for project2