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).
Types of client libraries
There are two types of client libraries available: Cloud Client Libraries and Google API Client Libraries. Both types support Application Default Credentials. For more information, see Client libraries explained.
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.
The preferred methods for setting up ADC are by using the gcloud CLI (for local development) or by using the attached service account (for production environments).
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 set up ADC for your environment and install the Cloud Storage client library.
Go
Java
Node.js
Python
Ruby
What's next
- Learn more about Application Default Credentials.
- See an overview of Authentication at Google.
- Review authentication use cases.