Using API Keys

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 only APIs needed for your application. Restricting API keys adds security to your application by protecting it from unwarranted requests. For more information, see API security best practices.

When you restrict your API key, you must provide the SHA-1 certificate fingerprint of the signing key that was used to sign the application. There are two certificate types:

  • Debug certificate: Only use this certificate type with apps you're testing and other non-production code. Do not attempt to publish an app that's signed with a debug certificate. The Android SDK tools generate this certificate automatically when you run a debug build.
  • Release certificate: Use this certificate when you're ready to release your app to an app store. The Android SDK tools generate this certificate when you run a release build.

For more information about Android application signing and certificates, see the Sign your app guide.

For instructions on how to find your signing certificate fingerprint, see the references below:

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. Select Android apps.
      2. Click + Add package name and fingerprint.
      3. Enter your package name and SHA-1 certificate fingerprint. For example:
        com.example.android.mapexample
        BB:0D:AC:74:D3:21:E1:43:67:71:9B:62:91:AF:A1:66:6E:44:5D:75
    • API restrictions:
      1. Click Restrict key.
      2. Select Navigation SDK from Select APIs drop-down. If the Navigation SDK is not listed, you need to enable it.
  4. To finalize your changes, click Save.

Cloud SDK

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/locations/global/keys/KEY_ID \
    --api-target=service=maps-android-backend.googleapis.com
    --allowed-application="sha1_fingerprint=SHA1_FINGERPRINT,package_name=ANDROID_PACKAGE_NAME"

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

What's next

Now that you have an API key, you can create and configure an Android Studio project. as described in Set Up an Android Studio Project.

Set up your Android Studio project