Crear credenciales con permisos
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Crea credenciales con permisos de las API de BigQuery y Drive.
Muestra de código
Salvo que se indique lo contrario, el contenido de esta página está sujeto a la licencia Atribución 4.0 de Creative Commons, y los ejemplos de código están sujetos a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","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)."]]