This page describes how you can use client libraries and Application Default Credentials to access Google APIs.
Client libraries make it easier to access Google Cloud APIs using a supported language. You can use Google Cloud APIs directly by making raw requests to the server, but client libraries provide simplifications that significantly reduce the amount of code you need to write. This is especially true for authentication, because the client libraries support Application Default Credentials (ADC).
If you want to use an API key, you don't use ADC. For more information, see Using an API key with client libraries.
Use Application Default Credentials with client libraries
To use Application Default Credentials to authenticate your application, you must first set up ADC for the environment where your application is running. When you use the client library to create a client, the client library automatically checks for and uses the credentials you have provided to ADC to authenticate to the APIs your code uses. Your application does not need to explicitly authenticate or manage tokens; these requirements are managed automatically by the authentication libraries.
For a local development environment, you can set up ADC with your user credentials or with service account impersonation by using the gcloud CLI. For production environments, you set up ADC by attaching a service account.
Example client creation
The following code samples create a client for the Cloud Storage service. Your code is likely to need different clients; these samples are meant only to show how you can create a client and use it without any code to explicitly authenticate.
Before you can run the following samples, you must complete the following steps:
Go
Java
Node.js
PHP
Python
Ruby
What's next
- Learn more about Application Default Credentials.
- See an overview of Authentication methods.