Click here to see your recently viewed pages and most viewed pages.
Hide

API Keys

This document describes API Keys, when to use them, how to acquire them, and how to use them with the Google APIs Client Library for Python.

Introduction

When calling an API that does not access private user data, you can use a simple API key. This key is used to authenticate your application for accounting purposes. The Google APIs Console documentation also describes API keys.

Note: If you do need to access private user data, you must use OAuth 2.0.

Acquiring API keys

  1. Go to the Google Developers Console.
  2. Select a project, or create a new one.
  3. In the sidebar on the left, expand APIs & auth. Next, click APIs. In the list of APIs, make sure all of the APIs you are using show a status of ON.
  4. In the sidebar on the left, select Credentials.
  5. Click Create new Key and select the appropriate key type:
    • Create and use a server key if your application runs on a server. Do not use this key outside of your server code. For example, do not embed it in a web page. To prevent quota theft, restrict your key so that requests are only allowed from your servers' source IP addresses.
    • Create and use a browser key if your application runs on a client, such as a web browser. To prevent your key from being used on unauthorized sites, only allow referrals from domains you administer.
    • Create and use an iOS key if your application runs on iOS devices. Google verifies that each request originates from an iOS application that matches one of the bundle identifiers you specify. An app's .plist file contains its bundle identifier. Example: com.example.MyApp
    • Create and use an Android key if your application runs on Android devices. To do so, you need to specify the SHA1 fingerprints and package names of the application using that key.

To keep your API keys secure, follow the best practices for securely using API keys.

Using API keys

To use an API key, pass it to the build() function when creating a service object. The Simple API Example on the Getting Started page provides a complete example that uses API keys. Here is the relevant line from that script:

service = build('books', 'v1', developerKey=api_key)

All calls made using that service object will include your API key.