Creare credenziali con ambiti
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Crea credenziali con gli ambiti delle API Drive e BigQuery.
Esempio di codice
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","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)."]]