2016-08-25 210 views
0

我是BigQuery的入門者。 而我的問題伴隨着身份驗證。 憑證文件已創建並存儲在:BigQuery身份驗證問題

/home/ltloi/.config/gcloud/application_default_credentials.json

內容:

{ 
    "type": "service_account", 
    "project_id": "xxx", 
    "private_key_id": "xxx", 
    "private_key": "-----BEGIN PRIVATE KEY-----xxx\n-----END PRIVATE KEY-----\n", 
    "client_email": "xxx", 
    "client_id": "xxx", 
    "auth_uri": "https://accounts.google.com/o/oauth2/auth", 
    "token_uri": "https://accounts.google.com/o/oauth2/token", 
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", 
    "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/bigqueryservices1%40neon-deployment-141106.iam.gserviceaccount.com" 
} 

源代碼:

// just authentication with google big query 
public static Bigquery createAuthorizedClient() throws IOException { 
    // Create the credential 
    HttpTransport transport = new NetHttpTransport(); 
    JsonFactory jsonFactory = new JacksonFactory(); 

    GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory); 

    // Depending on the environment that provides the default credentials (e.g. Compute Engine, App 
    // Engine), the credentials may require us to specify the scopes we need explicitly. 
    // Check for this case, and inject the Bigquery scope if required. 
    if (credential.createScopedRequired()) { 
     credential = credential.createScoped(BigqueryScopes.all()); 
    } 

    return new Bigquery.Builder(transport, jsonFactory, credential) 
     .setApplicationName("Bigquery Samples") 
     .build(); 
    } 

的問題問題:在 異常線程「主要」 java.io.IOException異常:錯誤的位置

閱讀證書文件

/home/ltloi/.config/gcloud/application_default_credentials.json

錯誤:

java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty at com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.getCredentialUsingWellKnownFile(DefaultCredentialProvider.java:251) at com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.getDefaultCredentialUnsynchronized(DefaultCredentialProvider.java:117) at com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.getDefaultCredential(DefaultCredentialProvider.java:91) at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.getApplicationDefault(GoogleCredential.java:213) at com.google.cloud.bigquery.samples.GettingStarted.createAuthorizedClient(GettingStarted.java:53) at com.google.cloud.bigquery.samples.GettingStarted.main(GettingStarted.java:135)

當我嘗試調試和代碼顯示帶有SSL發行形式的HttpClient。

請專家幫忙解決。我已經嘗試添加的 https://accounts.google.com/o/oauth2/auth

https://www.googleapis.com/oauth2/v1/certs

SSL卻不能解析。

我也安裝Cloud SDK,但也無法解決。

{ 
    "client_id": "XXXX", 
    "client_secret": "XXX", 
    "refresh_token": "XXXX", 
    "type": "authorized_user" 
} 

注:我已經做了gcloud公測身份驗證的應用程序的默認登錄gcloud公測身份驗證應用程序默認的打印訪問令牌

感謝&問候,

回答

0

被應用默認使用以下命令創建憑證?

gcloud beta auth application-default login 

我想還有兩個額外的快速測試,你可以做更接近的問題來源。首先,你可以試試這個,以驗證您的憑據都很好:

gcloud beta auth application-default print-access-token 

然後,你可以複製並粘貼此簡短的Python腳本,以驗證它的工作原理(從這裏開始:https://cloud.google.com/bigquery/authentication

# Grab the application's default credentials from the environment. 
credentials = GoogleCredentials.get_application_default() 
# Construct the service object for interacting with the BigQuery API. 
bigquery_service = build('bigquery', 'v2', credentials=credentials) 
+0

喜,gcloud beta auth application-default login&gcloud beta auth application-default print-access-token work is correct。 –

+0

同樣的問題,當我嘗試:https://cloud.google.com/dataflow/docs/quickstarts/quickstart-java-maven –