Anmeldedaten mit Bereichen erstellen
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Anmeldedaten mit Drive- und der BigQuery API-Bereichen erstellen
Codebeispiel
Nächste Schritte
Wenn Sie nach Codebeispielen für andere Google Cloud -Produkte suchen und filtern möchten, können Sie den Google Cloud -Beispielbrowser verwenden.
Sofern nicht anders angegeben, sind die Inhalte dieser Seite unter der Creative Commons Attribution 4.0 License und Codebeispiele unter der Apache 2.0 License lizenziert. Weitere Informationen finden Sie in den Websiterichtlinien von Google Developers. Java ist eine eingetragene Marke von Oracle und/oder seinen Partnern.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","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)."]]