AdMob API Java Samples
This collection of samples written in Java provide usage examples for the AdMob API.
Prerequisites
Please make sure that you're running Java 7+ and have Maven installed.
Setup Authentication
This API uses OAuth 2.0. See Using OAuth 2.0 to Access Google APIs to learn more.
To get started quickly, follow these steps.
- Visit https://console.developers.google.com to register your application.
- From the API Library, enable the AdMob API.
- Click on APIs & Services > Credentials in the left navigation menu.
- Click CREATE CREDENTIALS > OAuth client ID.
- Select Desktop app as the application type, give it a name, then click Create.
- From the Credentials page, click Download JSON next to the client ID you
just created and save the file as
client_secrets.json
in the /main/resources/ directory
Set up your environment
Via the command line
Execute the following command in the directory where the pom.xml
file exists. This file is found in the root directory of the AdMob API Java client library samples.
$ mvn compile
Via Intellij
Import the sample
- Select Import Project and find the root directory of the admob api samples on your machine.
- Select Import project from external model and Maven, then click Next.
- Check Import Maven projects automatically and Search for projects recursively, then click Next.
- Continue to click Next, until you can select Finish.
Running the Examples
Once you've checked out the code:
-
Open a sample and fill in any prerequisite values. Required values will be declared as constants near the top of the file.
-
Run the sample.
- Via Intellij, right-click on the sample and select Run <sample_name>.main().
-
Complete the authorization steps on your browser.
-
Examine the console output, and explore the AdMob API!