Tìm kiếm

Thứ Năm, 17 tháng 12, 2020

thumbnail

Get an API Key

 

Before you begin

Before you start using the Geocoding API, you need a project with a billing account and the Geocoding API enabled. To learn more, see Get Started with Google Maps Platform.

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:

  1. In the Cloud Console, on the project selector page, select or create a Google Cloud project for which you want to add an API Key.

    Go to the project selector page

  2. Go to the APIs & Services > Credentials page.

    Go to the Credentials page

  3. On the Credentials page, click Create credentials > API key.
    The API key created dialog displays your newly created API key.
  4. 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.)

Adding the API key to your request

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

https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY

Restricting API keys

Restricting API Keys adds security to your application by ensuring only authorized requests are made with your API Key. We strongly recommend that you follow the instructions to set restrictions for your API Keys. For more information, see API Key best practices.

To restrict an API key:

  1. In the Cloud Console, on the project selector page, select or create a Google Cloud project for which you want to add an API Key.

    Go to the project selector page

  2. Go to the APIs & Services > Credentials page.

    Go to the Credentials page

  3. Select the API key that you want to set a restriction on. The API key property page appears.
  4. 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.
      2. Specify one IPv4 or IPv6 address or a subnet using CIDR notation (e.g. 192.168.0.0/22). If you need to enter another entry, a new box appears after you complete adding the previous entry.
    • API restrictions:
      1. Click Restrict key.
      2. Select Geocoding API from Select APIs dropdown.
        (If the Geocoding API is not listed, you need to enable it.)
  5. To finalize your changes, click Save.

Troubleshooting authentication issues

If your request is malformed or supplies an invalid signature, the Geocoding API returns an HTTP 403 (Forbidden) error.

To troubleshoot individual URLs, you can use the URL Signing Debugger. It allows you to quickly validate a URL and signature generated by your application.

Premium Plan Customers and Migrated Customers

Premium Plan customers and customers who have migrated from the Premium Plan to the Google Maps Platform pay-as-you-go pricing model have the option to use an API key or a client ID to authenticate requests. For more information see Get API Keys Overview in the Premium Plan documentation.

Subscribe by Email

Follow Updates Articles from This Blog via Email

No Comments

Được tạo bởi Blogger.

Bài đăng tiêu biểu