Introduction and what are we going to cover
Hi my dear friends!
A while ago we were doing a fairly important feature for one of our clients which included integrating with Google’s Ads API. Seeing as the entire process was fairly cumbersome and took plenty of attempts to successfully accomplish - what with the official documentation being sorely lacking and difficult to wrap one’s head around to, I’ve decided to give a short tutorial to outline the necessary steps to get it working!
I hope it helps someone - if not, it might help me next time around!
In short, I will lead you through the process of setting up the Google Ads account so that you’re ready to “plug” the necessary credentials into your code, including how and where to grab or generate credentials and all the annoying bits.
The story began a couple of months ago with the requirement being that we integrate a large platform with the Google Ads API. Pretty quickly things turned sour and I had to face the harsh reality.
At a certain point I’ve started doubting myself and ended up feeling like I should seriously start seeking help, as Google didn’t offer any:
Luckily, I persevered in my attempts and eventually emerged as a winner (or at least I like to think so, stay tuned in case something changes 😭 ) so I have decided to be your light at the end of the tunnel and help you with setting up your own Google Ads API integration. One thing worth noting is that once you triumphantly latch onto Google’s API, it might just be the beginning of an entirely different story filled with pain and sorrow - at least it was for me!
Now, grab some popcorn and a couple of boxes of valium so we can start with this journey of ours!
Setup application
To get things off the ground you should create two email accounts on your Google Business account. The ones that I mention in the rest of the tutorial are private so you can’t make use of them.
The first account you create is to be used as the Google Ads manager. The second one will be the Google Ads user, with fewer permissions.
- Manager account (admin) : googleads-manager@kodius.com
- User account: googleads-user@kodius.com
Go to https://ads.google.com/home/tools/manager-accounts/ , sign in and make sure you fill in the necessary data
- Now you’ll be redirected to the main Ads page.
- Do note that you still don’t have billing info so you are unable to create ads until you’ve added a credit card to your account(Google will ask you to fill in billing info)
- Congrats! Now we have a clear path to becoming Google Ads masters (or managers :) ). Since you’ve successfully created a Google Ads account, you are now able to “create” campaigns through the Google Ads platform. From here on you can start with integrating the Google Ads API. Google gives you the Developer Console from which you are able to get the required credentials for integration. Easy peasy lemon squeezy! Or rather, stressed, depressed, lemon zest…
Fetch credentials
- Head over to the Developers Console (https://console.developers.google.com) and sign in with your manager account. Go to the credentials section (which should be blank as of right now seeing as your account is new and you don’t have any projects yet).
Create a project (I’ve called mine “Blog project” for the purposes of this tutorial)
Go to ‘library’ and make sure you’ve turned on Google Ads for your project
- Because we now have a project we are able to finally generate some credentials. Personally, I recommend you create all of them immediately as you don’t know when you’ll need them!
- When creating OAuth, choose your application type and create OAuth. From there you’ll get your client_id and client_secret. This is the first step towards getting the necessary Ads refresh-token.
- Note that for me, this script worked only for “Desktop” application type
This first part was the easiest part of connecting to the API, though. Now you will need to run a script to generate a refresh token.
- Head over to this repository(https://github.com/googleads/googleads-python-lib/blob/master/examples/adwords/authentication/generate_refresh_token.py) and download the python script
- Go into your console and run:
python3 ad_words_refresh_token.py --client_id {your client id} —client_secret {your client secret}
- You will get the following message:
- You’ll need to open up the URL that it spits out and then proceed with authorizing your Google account to get the code for your refresh token (ignore the unintelligible gibberish at the top of the screenshot, that’s just Croatian!)
- Copy and paste the provided string into your terminal:
- ….and now you’ll receive your brand new refresh and access tokens!
- For the developer token, head over to Ads manager Dashboard > Tools & Settings > API center
- Customer ID:
- Go to Ads manager Dashboard (top-right corner)
Congrats! You now have all the credentials you need for Google Ads API integration.
List of the credentials
- Client ID
- Client secret
- Access-token
- Refresh-token
- Developer token
- Customer ID
Conclusion and a few more notes
Your struggle is by no means over by finishing this tutorial. Now you need to give permission to your user account to be able to manage Google Ads. If you have any questions how to deal with that issue, feel free to reach out to me!
That being said, getting credentials from Google isn’t all that difficult (I might exaggerate a tiny bit), but it isn’t all that straightforward either, certainly not the way the Facebook Marketing API does it, for example.
Thanks for tuning in and feel free to contact me if you encounter any problems with your Ads integration (be it Google or even Facebook). If you do have questions, I’ll be sure to answer them and can go into much more depth if necessary!