Google Adwords API – Part 1
Google offers a lot of different services. Some of them have their own API to read data from external programs. One of them is AdWords.
AdWords uses SOAP interfaces to get data from campaigns and other things, but if you already worked with SOAP, this can be a hard job. For this you have a very good knowledge of the interface itself. The other problem is, that the API gets updates nearly every half year, so things can change. New values, deprecated values, …
If you do not have the time to study this interfaces, you may need the Client Library from Google. You can find the PHP Version here.
Adwords client library
One advantage of the library is, that you can get data much easier. The library has many examples of how to use special services and how to correctly use it. It is also discussed in many blogs and forums.
Installation
Very simple, you only need to download it and unzip it somewhere. You can easily use it from code.
How to work with the interface
If you want to use the PHP AdWords library, you have to include the AdWordsUser.php on top of your PHP file:
require_once 'Google_Adword_API/src/Google/Api/Ads/AdWords/Lib/AdWordsUser.php';
Then you need to create a AdWordsUser object:
$user = new AdWordsUser(null, $adwords_username, $adwords_password, $adwords_developerToken); $user->SetDefaultServer("https://adwords.google.com/");
An AdWordsUser object needs some values. These are:
- AdWords username
The username of your Google account, for which you registered your AdWords.
- Adwords Passwort
The password you set for the Google account. - Adwords developer token
A developer token which can be ordered here.
If your AdWords account is a so called MCC account, than there may be different AdWords account combined into one login. You can say that this is a top account to get data from multiple accounts with only one username and password (for example for customers of marketing and web agency).
Now we can connect with a registered account. For this we use the AdWords ID, which is unique for each AdWords account. You can find it on your Google AdWords user interface after login on the right top border. It looks like: XXX-XXX-XXXX. We copy this number into our code (without ‚-‚):
//set Adwords Client Id $user->SetClientId('1234567890');
You have now a ready configured user object. You can use it to get data from AdWords.
This was the first part. In the next part we start getting data from Google.
Part 2 | Part 3 | Part 4 | Part 5 | Part 6
Thank you for sharing.
Very helpful Tutorial.
After reading your post i could able to fix adwords api into codeigniter.
http://developer-paradize.blogspot.se
Regards,
Anup S
Hi. This is the best article I have found to get started working with this API. I am still having problems with the OAUTH part of the configuration. I am getting Uncaught exception ‚OAuth2Exception‘ with message ‚{ „error“ : „invalid_grant“ }. Any suggestions? Thank you.
Can tell me how adwords users can linked with MCC account using api thanks