Criar credenciais com escopos
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Crie credenciais com escopos das APIs do Drive e do BigQuery.
Exemplo de código
Exceto em caso de indicação contrária, o conteúdo desta página é licenciado de acordo com a Licença de atribuição 4.0 do Creative Commons, e as amostras de código são licenciadas de acordo com a Licença Apache 2.0. Para mais detalhes, consulte as políticas do site do Google Developers. Java é uma marca registrada da Oracle e/ou afiliadas.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis guide demonstrates how to create credentials with both Drive and BigQuery API scopes for accessing Google Cloud services.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code examples use Java and Python, and they require setting up Application Default Credentials for authentication to BigQuery.\u003c/p\u003e\n"],["\u003cp\u003eBoth the BigQuery and Drive APIs must be enabled for your project before running the sample codes, and the code samples reference the BigQuery quickstart and API reference documentation for additional assistance.\u003c/p\u003e\n"],["\u003cp\u003eThe code will initialize a client object to send requests or to interact with the BigQuery API.\u003c/p\u003e\n"],["\u003cp\u003eFor gcloud application default credentials, the user must authorize the application before, using a specific gcloud auth command.\u003c/p\u003e\n"]]],[],null,["# Create credentials with scopes\n\nCreate credentials with Drive and BigQuery API scopes.\n\nCode sample\n-----------\n\n### Java\n\n\nBefore trying this sample, follow the Java setup instructions in the\n[BigQuery quickstart using\nclient libraries](/bigquery/docs/quickstarts/quickstart-client-libraries).\n\n\nFor more information, see the\n[BigQuery Java API\nreference documentation](/java/docs/reference/google-cloud-bigquery/latest/overview).\n\n\nTo authenticate to BigQuery, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for client libraries](/bigquery/docs/authentication#client-libs).\n\n GoogleCredentials credentials =\n ServiceAccountCredentials.getApplicationDefault()\n .createScoped(\n ImmutableSet.of(\n \"https://www.googleapis.com/auth/bigquery\",\n \"https://www.googleapis.com/auth/drive\"));\n\n // Initialize client that will be used to send requests. This client only needs to be created\n // once, and can be reused for multiple requests.\n BigQuery bigquery =\n BigQueryOptions.newBuilder().setCredentials(credentials).build().getService();\n\n### Python\n\n\nBefore trying this sample, follow the Python setup instructions in the\n[BigQuery quickstart using\nclient libraries](/bigquery/docs/quickstarts/quickstart-client-libraries).\n\n\nFor more information, see the\n[BigQuery Python API\nreference documentation](/python/docs/reference/bigquery/latest).\n\n\nTo authenticate to BigQuery, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for client libraries](/bigquery/docs/authentication#client-libs).\n\n from google.cloud import https://cloud.google.com/python/docs/reference/bigquery/latest/\n import google.auth\n\n # Create credentials with Drive & BigQuery API scopes.\n # Both APIs must be enabled for your project before running this code.\n #\n # If you are using credentials from gcloud, you must authorize the\n # application first with the following command:\n #\n # gcloud auth application-default login \\\n # --scopes=https://www.googleapis.com/auth/drive,https://www.googleapis.com/auth/cloud-platform\n credentials, project = google.auth.default(\n scopes=[\n \"https://www.googleapis.com/auth/drive\",\n \"https://www.googleapis.com/auth/cloud-platform\",\n ]\n )\n\n # Construct a BigQuery client object.\n client = https://cloud.google.com/python/docs/reference/bigquery/latest/.https://cloud.google.com/python/docs/reference/bigquery/latest/google.cloud.bigquery.client.Client.html(credentials=credentials, project=project)\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=bigquery)."]]