[MUSIC PLAYING]
Hi, I'm Xeres, a developer advocate here at Google,
back again in our AdWords API series.
In the first video, we looked at what the AdWords API is
and what it can be used for.
In this video, I want to get you to your first API call.
This is a complex process, so I wanted to break it down
for you, step by step.
You may want to pause the video from time to time
so that you can follow along.
This will open the door for you to take full advantage
of the AdWords API.
We're going to use Java and Eclipse.
If you don't use Java, you can accomplish
all of this with the client libraries
in these other languages.
The concepts are all the same.
Here are the six steps you need to follow-- request
a developer token, create a test AdWords MCC
or My Client Centered Account and a test AdWords client
account, set up your development environment,
set up OAuth2 access, configure your client application,
and, finally, make your first API call.
So let's start.
To be able to use the AdWords API,
you need to have an AdWords MCC account.
If you don't have one, you can request one here.
Next, request a developer token.
This is what allows your application
to connect to the API.
Log into your AdWords MCC account.
In the gear menu, choose Account Settings.
Then, in the menu on the left, click AdWords API Center
and fill out the form to apply for a developer token.
Check your mail for another application form
and complete it.
You should receive it within two business days.
You can also find that form here.
While your developer token is pending approval,
you can start using it to develop your code with a test
MCC account.
API calls you make to the test MCC account will not
serve any ads.
Use this link to create your test MCC account.
After you create it, use the AdWords web interface
to create a test client account, under that test MCC account.
And in that test client account, create a few test campaigns
and save the client account customer ID for later.
Now, let's turn our attention to your development environment.
If you're an experienced Java developer,
you probably already have your environment just the way
you want it.
If not, we will walk through the recommended set
up for the Java client libraries now.
First, install Eclipse from here.
Eclipse for Java EE is recommended,
because it includes Maven.
Then, download the Maven AdWords client library for Java
from here.
The client library handles all the back end API calls for you
and exposes friendly objects to work with.
This particular archive also includes code samples
which are very helpful.
Extract the files and open them in Eclipse by choosing Import,
Existing Maven Project.
If you get Maven compilation errors,
you may have to install additional M2E connectors
for Eclipse.
If you still have some errors in the palm.XML,
you can ignore them.
The code samples should still run properly.
Now, let's move on to setting up OAuth2.
The average API using OAuth2 to allow your application
to operate on behalf of your AdWords account.
To get set up, follow these steps.
Go to the Google Developer Console
and login with your MCC credentials.
Create a new project, go to APIs & Auth in the left menu
and select Credentials.
Follow the workflow to create a new client ID
and, when prompted, choose Installed Application
as the application type and Other
as the installed application type.
It will then display your newly created client ID, client
secret, and redirect URIs.
Save these for later as well.
Just a quick note that client here
means your application, not the AdWords MCC or client account.
Now, let's go back to Eclipse.
In the client library and samples project,
open the Ads.Properties file here.
Now you'll need all of these values
that we've been saving for later.
First, enter your developer token on this line.
It's OK if it's not approved yet,
since we're using a test account customer ID.
Then, enter your test client customer ID on this line.
Enter your OAuth2 client ID and client secret on these lines.
Then enter the name of your application or organization
on this line.
You can leave any other values at their defaults.
You'll notice that there is a line for a refresh token.
This token is used by the client library
to generate new OAuth tokens, as needed.
The client library has a utility to retrieve that refresh token,
which we can use now.
In Eclipse, find GetRefreshToken.Java
and execute it.
The Eclipse console will print a URL.
Open a browser and log into AdWords
with your test MCC account.
Then, copy that URL into the browser.
Click Accept and copy the code back into the Eclipse console
where prompted.
The console will then print a refresh token.
Copy that into the Ads.Properties file.
I know.
It's a lot, right?
But this file should now contain all the necessary information
to make API calls against your test AdWords client account.
So, in Eclipse, open up GetCampaigns.Java
and execute it.
The console should print a listing of the test campaigns
in your test account.
Congratulations.
You just made an API call with the client library.
It was a long journey, but now, you're
ready to explore the power of the AdWords API.
Thanks for watching and this will all be worth it,
I promise.
[MUSIC PLAYING]