> [!IMPORTANT]
> **Important:** New user roles and permissions will affect data returned by the AdMob API. [Learn more](https://support.google.com/admob/answer/2784628)

This guide is for developers who want to use the AdMob API to
programmatically get
data in their AdMob account.

All Google AdMob API calls must be authorized through
[OAuth2](https://developers.google.com/identity/protocols/oauth2) so your app can interact with web services
on the user's behalf. OAuth2 enables your AdMob API client app to access a
user's AdMob account without having to handle or store the user's username or
password. For an overview of authorization, see
[Authorization](https://developers.google.com/admob/api/v1/how-tos/authorizing).

Perform the following steps to generate the OAuth2 credentials and make your
first request.

## Prerequisites

- A [Google Account](https://google.com/accounts/NewAccount).

- A [Google AdMob account](https://admob.google.com/home/get-started).

- Familiarity with [REST basics](https://developers.google.com/admob/api/v1/prereqs#rest) and [authorizing requests with
  OAuth 2.0](https://developers.google.com/admob/api/v1/how-tos/authorizing).

## Determine your authentication type

Check the table below to see which **authentication type** is most appropriate
for your app:

| Choose your OAuth2 authentication type | If ... |
|---|---|
| **Desktop app** | - You're managing all of your AdMob API accounts using a single top level manager account. - You're a first-time user, or want to get started quickly with the simplest setup. - Your app only authenticates Google AdMob users from one machine. |
| **Web app** | - You want to authenticate as a user who can grant permission to your app to access their AdMob API account data. - You want to easily generate multiple authorization credentials, to manage third-party accounts for example. - Your app requires callback URLs. Callback URLs are not supported in the desktop app flow. |

> [!IMPORTANT]
> **Key Point:** You can still choose the desktop app flow even if you're developing an app to run on a server. The difference is whether the OAuth authorization is completed locally or remotely. A desktop flow requires authorization to be completed on the local machine, whereas the web-flow lets authorization be completed on Google's authorization server.

## Create a project

To get started using the AdMob API, you need to first create or select a
project in the Google API Console and enable the API using [the setup
tool](https://console.cloud.google.com/start/api?id=admob.googleapis.com&amp;credential=client_key),
which guides you through the process and activates the AdMob API
automatically.

#### Enabling the API for an existing project

The following steps apply to users who have an existing project and prefer to
activate the AdMob API for it manually.

To enable an API for your project:

1. [Open the API Library](https://console.developers.google.com/apis/library) in the Google API Console.
2. If prompted, select a project, or create a new one. The API Library lists all available APIs, grouped by product family and popularity.
3. If the API you want to enable isn't visible in the list, use search to find it, or click **View All** in the product family it belongs to.
4. Select the API you want to enable, then click the **Enable** button.
5. If prompted, enable billing.
6. If prompted, read and accept the API's Terms of Service.

## Create OAuth2 credentials

The following instructions guide you through the process of creating an OAuth
2.0 client ID to use with the [installed app
flow](https://developers.google.com/identity/protocols/OAuth2InstalledApp).

1. Go to the [Clients page](https://console.developers.google.com/auth/clients).

2. Click **CREATE CREDENTIALS \> OAuth client ID**.

   If you hadn't configured an OAuth consent screen for this project
   previously, you'll be directed to do so now. Click **CONFIGURE CONSENT
   SCREEN**. There are multiple ways to configure your consent screen to
   use your OAuth 2.0 client ID.
   1. Set your user type to **External** and publishing status to **Published**.
   2. Or, set your user type to **External** and publishing status to
      **Testing** , then add **Test users** by selecting **add users** to
      give them access to use your OAuth 2.0 client ID.

      See additional information on [setting up your OAuth consent
      screen](https://support.google.com/cloud/answer/10311615).
3. Select **Desktop app** or **Web Application** as the application type, give
   it a name, then click **Create**.

When done, you are presented with an OAuth 2.0 client ID and client secret,
which you can download in JSON format and save for later use.

## Make a request

The AdMob API is built on HTTP and JSON, so any standard HTTP client can send
requests to it and parse the responses. However, the [Google API client
libraries](https://developers.google.com/admob/api/v1/libraries) provide better language integration,
improved security, and support for making authorized requests. The client
libraries are available in a number of programming languages; by using them you
can avoid the need to manually set up HTTP requests and parse the responses.

> [!NOTE]
> **Note:** The first time you activate the OAuth flow, you are asked to provide your AdMob publisher ID and accept an authorization prompt in your browser. Before accepting, make sure you're signed in with a Google Account that has access to your AdMob account. Your app is then authorized to access data on behalf of whichever account is currently logged in.

With [OAuth 2.0 credentials created](https://developers.google.com/admob/api/v1/getting-started#credentials), you're ready to start using
the AdMob API. To request access using OAuth 2.0, your app also needs scope
information:


| Scope | Meaning |
|---|---|
| `https://www.googleapis.com/auth/admob.readonly` | See all AdMob data. This may include account information, inventory and mediation settings, reports, and other data. This doesn't include sensitive data, such as payments or campaign details. |
| `https://www.googleapis.com/auth/admob.report` | See ad performance and earnings reports. See publisher ID, timezone, and default currency code. |

<br />

<br />

Make your first request to generate a report using examples in
[Java](https://developers.google.com/admob/api/v1/reporting#java-client-library),
[PHP](https://developers.google.com/admob/api/v1/reporting#php-client-library),
[Python](https://developers.google.com/admob/api/v1/reporting#python-client-library) or
[curl](https://developers.google.com/admob/api/v1/reporting#curl-command-line).

## Revoke shared tokens

You can revoke shared tokens in two ways:

1. Navigate to your [Google account
   permissions page](https://myaccount.google.com/permissions) and revoke access from
   the relevant project.

2. Alternatively, you can revoke web application tokens using the [Google
   Identity API](https://developers.google.com/identity/protocols/oauth2/web-server#tokenrevoke).