BigQuery身份验证问题

时间:2016-08-25 10:53:14

标签: google-bigquery google-cloud-platform google-oauth2

我是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();
  }

问题问题:  线程“main”中的异常java.io.IOException:从位置读取凭据文件时出错

  

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

错误:

  

java.lang.RuntimeException:意外错误:java.security.InvalidAlgorithmParameterException:trustAnchors参数必须为非空           在com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.getCredentialUsingWellKnownFile(DefaultCredentialProvider.java:251)           在com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.getDefaultCredentialUnsynchronized(DefaultCredentialProvider.java:117)           在com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.getDefaultCredential(DefaultCredentialProvider.java:91)           在com.google.api.client.googleapis.auth.oauth2.GoogleCredential.getApplicationDefault(GoogleCredential.java:213)           在com.google.cloud.bigquery.samples.GettingStarted.createAuthorizedClient(GettingStarted.java:53)           在com.google.cloud.bigquery.samples.GettingStarted.main(GettingStarted.java:135)

当我尝试调试时,代码显示附带SSL问题表格HttpClient。

专家请帮忙解决。我试着添加SSL https://accounts.google.com/o/oauth2/auth

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

但无法解决。

我也安装了Cloud SDK,但也无法解决。

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

注意:我已完成 gcloud beta auth application-default login gcloud beta auth application-default print-access-token

谢谢&的问候,

1 个答案:

答案 0 :(得分: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)