使用应用默认凭据创建客户端

使用应用默认凭据创建 BigQuery 客户端。

深入探索

如需查看包含此代码示例的详细文档,请参阅以下内容:

代码示例

Java

试用此示例之前,请按照 BigQuery 快速入门:使用客户端库中的 Java 设置说明进行操作。 如需了解详情,请参阅 BigQuery Java API 参考文档

如需向 BigQuery 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为客户端库设置身份验证

public static void implicit() {   // Instantiate a client. If you don't specify credentials when constructing a client, the   // client library will look for credentials in the environment, such as the   // GOOGLE_APPLICATION_CREDENTIALS environment variable.   BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();    // Use the client.   System.out.println("Datasets:");   for (Dataset dataset : bigquery.listDatasets().iterateAll()) {     System.out.printf("%s%n", dataset.getDatasetId().getDataset());   } }

Node.js

试用此示例之前,请按照 BigQuery 快速入门:使用客户端库中的 Node.js 设置说明进行操作。 如需了解详情,请参阅 BigQuery Node.js API 参考文档

如需向 BigQuery 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为客户端库设置身份验证

// Import the Google Cloud client library using default credentials const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery();

PHP

试用此示例之前,请按照 BigQuery 快速入门:使用客户端库中的 PHP 设置说明进行操作。 如需了解详情,请参阅 BigQuery PHP API 参考文档

如需向 BigQuery 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为客户端库设置身份验证

use Google\Cloud\BigQuery\BigQueryClient;  /** Uncomment and populate these variables in your code */ //$projectId = 'The Google project ID';  $bigQuery = new BigQueryClient([     'projectId' => $projectId, ]);

Python

试用此示例之前,请按照 BigQuery 快速入门:使用客户端库中的 Python 设置说明进行操作。 如需了解详情,请参阅 BigQuery Python API 参考文档

如需向 BigQuery 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为客户端库设置身份验证

from google.cloud import bigquery  # If you don't specify credentials when constructing the client, the # client library will look for credentials in the environment. client = bigquery.Client()

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅Google Cloud 示例浏览器