Instructions for the AdSense Host API V4.1 Command-Line Sample
Browse Online
Register Your Application
- Visit the Google
APIs console
- If this is your first time, click "Create project..."
- Click on "API Access", and then on "Create an OAuth 2.0 Client
ID...".
- Enter a product name and click "Next".
- Select "Installed application" and click "Create client ID".
- Enter the "Client ID" and "Client secret" shown under "Client ID
for installed applications" into src/main/resources/client_secrets.json
file after checking out the code (otherwise you will get a
400
INVALID_CLIENT error in the browser when running the sample).
Checkout Instructions
Prerequisites: install Java 6, Mercurial, and Maven. You may need to
set your
JAVA_HOME
.
cd [someDirectory]
hg clone https://code.google.com/p/google-api-java-client.samples/ google-api-java-client-samples
cd google-api-java-client-samples/adsensehost-cmdline-sample
[editor] src/main/resources/client_secrets.json
[editor] src/main/java/com/google/api/services/samples/adsensehost/cmdline/AdSenseHostSample.java
(Set PUB_ACCOUNT_ID to your publisher account ID if you want the
publisher samples to run)
mvn compile
mvn -q exec:java
Setup Project in Eclipse
To enable logging of HTTP requests and responses (highly recommended
when developing), please take a look at logging.properties.
Prerequisites: install Eclipse,
the Mercurial plugin, and the
Maven
plugin.
- Setup Eclipse Preferences
- Window > Preferences... (or on Mac, Eclipse >
Preferences...)
- Select Maven
- check on "Download Artifact Sources"
- check on "Download Artifact JavaDoc"
- Import
adsensehost-cmdline-sample project
- File > Import...
- Select "General > Existing Project into Workspace" and click
"Next"
- Click "Browse" next to "Select root directory", find
[someDirectory]/google-api-java-client-samples/adsensehost-cmdline-sample
and click "Next"
- Click "Finish"
- Run
- Right-click on project adsensehost-cmdline-sample
- Run As > Java Application
- If asked, type "AdSenseHostSample" and click OK