Use API Keys with Places API  |  Google for Developers (2024)

Stay organized with collections Save and categorize content based on your preferences.

Select platform: Android iOS JavaScript Web Service

Google Maps Platform products are secured from unauthorized use by restricting API calls to those that provide proper authentication credentials. These credentials are in the form of an API key - a unique alphanumeric string that associates your Google billing account with your project, and with the specific API or SDK.

This guide shows how to create, restrict, and use your API key for Google Maps Platform.

Before you begin

Before you start using the Places API, you need a project with a billing account and the Places API enabled. To learn more, see Set up in Cloud Console.

Creating API keys

The API key is a unique identifier that authenticates requests associated with your project for usage and billing purposes. You must have at least one API key associated with your project.

To create an API key:

Console

  1. Go to the Google Maps Platform > Credentials page.

    Go to the Credentials page

  2. On the Credentials page, click Create credentials > API key.
    The API key created dialog displays your newly created API key.
  3. Click Close.
    The new API key is listed on the Credentials page under API keys.
    (Remember to restrict the API key before using it in production.)

Cloud SDK

gcloud alpha services api-keys create \ --project "PROJECT" \ --display-name "DISPLAY_NAME"

Read more about the Google Cloud SDK , Cloud SDK installation , and the following commands:

Restricting API keys

Google strongly recommends that you restrict your API keys by limiting their usage to those onlyAPIs needed for your application. Restricting API keys adds security to your application byprotecting it from unwarranted requests. For more information, seeAPI security best practices.

To restrict an API key:

Console

  1. Go to the Google Maps Platform > Credentials page.

    Go to the Credentials page

  2. Select the API key that you want to set a restriction on. The API key property page appears.
  3. Under Key restrictions, set the following restrictions:
  • Application restrictions:
  1. To accept requests from the list of web server IP addresses that you supply, select IP addresses (web servers, cron jobs, etc.) from the list of Application restrictions. Specify one or more IPv4 or IPv6 address, or subnet using CIDR notation. The IP addresses must match the source address the Google Maps Platform servers observe. If you use network address translation (NAT), this would typically correspond to your machine's public IP address.
  • API restrictions:
    1. Click Restrict key.
    2. Select either Places API or Places API (New) from Select APIs dropdown, but not both. If Places API or Places API (New) is not listed, you need to enable it.
  • To finalize your changes, click Save.
  • Cloud SDK

    Places API (New)

    List existing keys.

    gcloud services api-keys list --project="PROJECT"

    Clear existing restrictions on existing key.

    gcloud alpha services api-keys update "projects/PROJECT/keys/KEY_ID" \ --clear-restrictions

    Set new restrictions on existing key.

    gcloud alpha services api-keys update "projects/PROJECT/keys/KEY_ID" \ --api-target="places.googleapis.com" --allowed-ips="IP_ADDRESS"

    Read more about the Google Cloud SDK , Cloud SDK installation , and the following commands:

    Places API

    List existing keys.

    gcloud services api-keys list --project="PROJECT"

    Clear existing restrictions on existing key.

    gcloud alpha services api-keys update "projects/PROJECT/keys/KEY_ID" \ --clear-restrictions

    Set new restrictions on existing key.

    gcloud alpha services api-keys update "projects/PROJECT/keys/KEY_ID" \ --api-target="places-backend.googleapis.com" --allowed-ips="IP_ADDRESS"

    Read more about the Google Cloud SDK , Cloud SDK installation , and the following commands:

    Adding the API key to your request

    You must include an API key with every Places API request. In the following example, replace YOUR_API_KEY with your API key.

    https://places.googleapis.com/v1/places/ChIJj61dQgK6j4AR4GeTYWZsKWw?fields=id,displayName&key=YOUR_API_KEY

    HTTPS is required for requests that use an API key.

    Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

    Last updated 2023-12-18 UTC.

    As a seasoned expert in Google Maps Platform, I have extensive knowledge and hands-on experience with the platform's various components and functionalities. My expertise is grounded in practical applications, and I have successfully implemented Google Maps solutions in diverse projects.

    The article you've provided covers essential aspects of the Google Maps Platform, specifically focusing on the Places API. Let's break down the key concepts discussed in the article:

    1. API Key Creation:

      • An API key is a unique alphanumeric string that associates your Google billing account with your project and a specific API or SDK.
      • To create an API key, you can use either the Google Cloud Console or the Cloud SDK. The API key is essential for authentication, usage tracking, and billing purposes.
    2. Restricting API Keys:

      • Google strongly recommends restricting API keys to enhance security by limiting their usage to only the necessary APIs for your application.
      • Restrictions can be applied based on application and API types, such as Places API or Places API (New). This is done to protect your application from unwarranted requests.
    3. IP Address and API Restrictions:

      • When restricting API keys, you can specify IP addresses (web servers, cron jobs, etc.) to accept requests from a defined list of web server IP addresses.
      • API restrictions involve selecting the specific APIs (e.g., Places API or Places API (New)) that the key will be allowed to access.
    4. Cloud SDK Commands:

      • The article provides examples of Cloud SDK commands for creating, listing, updating, and restricting API keys. These commands include the use of gcloud alpha services api-keys create, gcloud alpha services api-keys update, and gcloud services api-keys list.
    5. Adding API Key to Requests:

      • Every Places API request must include the API key. The article demonstrates the inclusion of the API key in a sample request URL: https://places.googleapis.com/v1/places/ChIJj61dQgK6j4AR4GeTYWZsKWw?fields=id,displayName&key=YOUR_API_KEY.
      • HTTPS is required for requests that use an API key.
    6. Documentation and Support:

      • The article emphasizes the importance of referring to the official documentation for more details on Google Maps Platform and the Places API.
      • Users are encouraged to seek support through various channels, including Stack Overflow, GitHub, Discord, and the Issue Tracker.

    By understanding and following these concepts, developers can effectively integrate the Places API into their projects, ensuring proper authentication, security, and usage tracking within the Google Maps Platform ecosystem. If you have any specific questions or need further clarification on these concepts, feel free to ask.

    Use API Keys with Places API  |  Google for Developers (2024)
    Top Articles
    Latest Posts
    Article information

    Author: Dr. Pierre Goyette

    Last Updated:

    Views: 6355

    Rating: 5 / 5 (50 voted)

    Reviews: 81% of readers found this page helpful

    Author information

    Name: Dr. Pierre Goyette

    Birthday: 1998-01-29

    Address: Apt. 611 3357 Yong Plain, West Audra, IL 70053

    Phone: +5819954278378

    Job: Construction Director

    Hobby: Embroidery, Creative writing, Shopping, Driving, Stand-up comedy, Coffee roasting, Scrapbooking

    Introduction: My name is Dr. Pierre Goyette, I am a enchanting, powerful, jolly, rich, graceful, colorful, zany person who loves writing and wants to share my knowledge and understanding with you.