Create credentials with Drive and BigQuery API scopes.
For detailed documentation that includes this code sample, see the following:
Before trying this sample, follow the Java setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Java API reference documentation.
GoogleCredentials credentials = ServiceAccountCredentials.getApplicationDefault() .createScoped( ImmutableSet.of( "https://www.googleapis.com/auth/bigquery", "https://www.googleapis.com/auth/drive")); // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. BigQuery bigquery = BigQueryOptions.newBuilder().setCredentials(credentials).build().getService();
Before trying this sample, follow the Python setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Python API reference documentation.
from google.cloud import bigquery import google.auth # Create credentials with Drive & BigQuery API scopes. # Both APIs must be enabled for your project before running this code. # # If you are using credentials from gcloud, you must authorize the # application first with the following command: # # gcloud auth application-default login \ # --scopes=https://www.googleapis.com/auth/drive,https://www.googleapis.com/auth/cloud-platform credentials, project = google.auth.default( scopes=[ "https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/cloud-platform", ] ) # Construct a BigQuery client object. client = bigquery.Client(credentials=credentials, project=project)
To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.