Map Management API supports the use of OAuth 2.0 for authentication. Google supports common OAuth 2.0 scenarios, such as those for a web server.
This document describes how to pass an OAuth token to the Map Management API call in your development environment. For instructions on using OAuth in a production environment, see Authentication at Google.
Before you begin
Before you start using Map Management API, you need a project with a billing account and Map Management API enabled. For more information, see Set up in Cloud Console.
About OAuth
You can create and manage access tokens with OAuth in several ways depending on your deployment environment.
For example, the Google OAuth 2.0 system supports server-to-server interactions, such as those between your application and a Google service. For this scenario, you need a service account. This account belongs to your application instead of an individual user. Your application calls Google APIs on behalf of the service account because users aren't directly involved. For more information about authentication methods, see Authentication at Google.
Alternatively, you can use Map Management API as part of an Android or iOS mobile app. For more information about using OAuth with Map Management API, including information about managing access tokens for different deployment environments, see Using OAuth 2.0 to Access Google APIs.
About OAuth scopes
To use OAuth with the Map Management API, the OAuth token must have the
scope https://www.googleapis.com/auth/cloud-platform.
Try REST API calls in your local development environment
If you want to try the Map Management API using an OAuth token, but don't have an environment set up to generate tokens, you can use the procedure in this section to make the call.
This example describes how to use the OAuth token provided by Application Default Credentials (ADC) to make the call. For more information about using ADC to call Google APIs with client libraries, see Authenticate using client libraries.
Prerequisites
Before you can make a REST request using ADC, use the Google Cloud CLI to provide credentials to ADC:
- If you haven't already, create a project and enable billing by following the steps in Set up in Cloud Console.
- Install and initialize the gcloud CLI.
To create your credential file, run the
gcloudcommand on your local machine:gcloud auth application-default login
- When prompted, sign in. After you sign in, your credentials are stored in the local credential file used by ADC.
For more information, see the Local development environment section of the Provide credentials for Application Default Credentials documentation.
Make a REST request
In this example, you pass two request headers:
Pass the OAuth token in the
Authorizationheader by using the following command to generate the token:gcloud auth application-default print-access-tokenThe returned token has a scope of
https://www.googleapis.com/auth/cloud-platform.- Pass the ID or name of your Google Cloud project that has billing enabled
in the
X-Goog-User-Projectheader. For more information, see Set up in Cloud Console.
Make a call to the Map Management API by using an OAuth token:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \ -H "X-Goog-User-Project: PROJECT_ID" \ https://mapmanagement.googleapis.com/v2beta/projects/PROJECT_NUMBER_OR_ID/mapConfigs/
Troubleshooting
If your request returns an error message about user credentials not being supported by this API, see User credentials not working.