Google Ads Automation with Python - How to Connect to API Tutorial (#1)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
my name is roman and it's marketing watch house and welcome back on the channel and today we are going to start our long awaiting series on how to connect to google ads api with python and the reason why it took me so long more than uh a few more a year probably to actually come to back to this topic and start doing it it's because to just to start interacting with google ads api through python and working with your real client account it takes so much effort and from my own personal view it takes a lot of effort compared to facebook to microsoft to apple search ads like none of those system requires you to go so much into details and like understanding how to make it work but the good news is that this is a test example of some python script i took from the website and it actually works on my local machine which is enormous success for me guys i can honestly tell to you that i was so happy to make it work after so long and the problem is like throughout the time throughout the last year they updated the library and i'm not no longer any good with the like latest examples so it will take some time for me to actually understand how it works but what we're going to do right now is to make your machine working with google ads api and from my point of view from what i see on youtube on the internet it's the most complicated question it's not like to interact with api but to just to make it to gain access to that and the reason why it's so complicated is because you need this file this file is called google ads yaml it can be called whatever you want but it's a yaml file it's very famous and first of all you will see two different types of yaml files on the internet one is not not going to have anything in the very beginning so it's going to be just the file and the other one is going to have google ads colon and then the parameters sorry google adwords it's the old one and i'm no longer interested in that one so systematically these two files are exactly the same the only difference that the up-to-date file doesn't have this line and the latest library doesn't require this line to exist so what you're going to have is this file that you can download from the description below or you also can download on the website where the library exists uh which must be somewhere not far away i guess uh yeah i will show it just in a bit so to make it work what we need first is to make sure that you have python 3.7 or later to do that we're going to go and say download python i would recommend you to take the latest version which is 3.8 or 3.9 and just use that one you also need somewhere to write the code and i personally recommend you to go for pycharm community edition this is more than enough you don't need to have a professional if you're just starting doing this which is going to be download and here is going to be sorry this is the community edition so installing these two things will give you an access to python itself and somewhere to code and after you start your pie chart what you need to do is to do a new project in the very beginning pick the folder you wanted to make it work in and all these details but like there are a lot of tutorials on that how to make it work and if you have any problems which you shouldn't have but in case because all machines are different just you 100 will find the solution out there but after you did all of this what you need to do is to install a library called if i'm not mistaken let me check here yeah it's going to be google ads library and the easiest way to install it inside your pycharm is on the very top if i just close all my folders you will see this is the project file i have and there is another file that just under the project file which is called requirements.txt and all you need to do is just to write these three lines here which is going to be pandas google ads and google dash ads and that will automatically pop up for example if i do google ads as you will have a pop-up uh asking your permission to install a missing library and this is the easiest way to install library in pycharm by the way after you do that you almost have everything you need on the technical side and we come to much more difficult much more uh painful part of filling this file so what this file is is it's actually an access card something that gives you script all the need inform all all the information the script needs to an access to google ads and what this file why this file is different from what you will see in apple search ads or in microsoft and any other system including yandex is that it requires two different tokens instead of one which is from my point of view is unusual so talking is like a secret password that will allow you to access google ads and the one one talking that you need is going to give you an access to google account in general to your email to your whatever you want and another token will define how much things you can change in google ads and this one that will define how much things you need to you will be able to change in google ads is actually developer token and the file the talking that we just given access to google in general is sorry is a client id client secret and refresh token so first of all you need to make sure that you have developer token and to do that what you need to do is to go to google ads account to your mcc i don't know if this is possible to be to implement inside the just client account but i assume that in most cases you're going to have the mcc then you go to tools and settings and here you're going to have api center and here you see uh there is my there is my developer talking and there is an access that is called basic access and there is a apply for standard access when you come to this website you will not see uh your talking being here what you need to do is to request the token you will have a button here which is going to have a restricted level like a [Music] sandbox or something you will not have a basic access just from the very beginning to actually have a basic access you will need you will have a link here to fill the form which i guess is going to be yeah this is the form you will have to feel and this form has a lot of questions to fill in about who you are what your company is working do you manage your clients or do you manage your own accounts this is quite a big form and unless you feel it and it got approved there is no way you can access google ads uh directly you only can access the test account that you need to create later so i was very afraid of this because like a lot of questions here just do not like feel under what i'm doing here what i'm usually do and it took me quite a while to figure out what they're actually looking for but in general this form is not very complicated what you need specifically to take into account that you need specifically to write down what is your business what you're working on are you a client or you're an agency do you plan to mutate or change anything actively inside your accounts or do you want to only reporting access do you plan to access the uh forecasting tool or you do not need that and a few other questions and if you feel it like properly then even if you miss something they will follow you up and say okay we don't see this this and this information here and then you just can reply to the uh email so this is the example of questions that i failed to answer do you plan to do any keyword research via in the api specifically do you plan to use targeting id service or traffic estimation service and both of these both of these services have a direct relation to google keyword planner so when you fill this form be very very careful uh the most difficult part i guess is upload the design documentation of your tool must be in pdf doc or rtf file formats only and there is an example of the file they're sharing and this example contains the all the questions you need to feel and be very careful when you fill these questions try not to use any double meanings or anything at all like you can write the same thing twice or three times just to make it clear because after all uh this form is going to be uh read by people that have lots of forms to process they just need to find out what's the overall information do you try to sell this tool do you do it for public or for private only and this kind of stuff and in the very end there is a two mock-up stuff and this is where i failed i i actually failed to to read this down because when you scroll down there is an example that i totally forgot to delete and whereas i claim that my tool is not gonna have any interface this picture was inside and they were very confused with that so if you don't have if you only plan to use the internal ad hoc solution then don't forget to remove this visual pictures here they yeah they just they just cost me like a week of my life but whatever after you feel this form and you send it out in a few days or in a week you're gonna have a confirmation a rejection or they will ask for additional information and you will have a developer talking here uh which you gonna copy and then paste inside the developer talking this is this is the easiest part i would say uh this is the difficult the most difficult part sorry so another thing you need to do is a login customer id this is your uh if i'm not mistaking this is your mcc id which you can just copy from there paste here and don't forget that it should be just a number with no dash lines or anything like this so this is the login customer id then there is another parameter validate only false that you can just keep it as it is and then we come to the last three lines and these three lines uh are gonna give us an access to google itself so to do that first of all we need to generate client id and client secret and then separately we need to generate the refresh token and this is the most difficult part that you need to generate this separately and it's not very easy to find out all the information about it so to do that what we need to actually do is to go to this page which is going to be linked into description and here the google ads define how to get an access to how to get this token it's called all through all author okay authentication and here we have installed app and this is what i'm going for i'm trying to make an ad hoc solutions ad hoc solutions with a lot of scripts that i'm going to run and get some data from the google ads and maybe mutate something but i'm not going to make a web app i'm not going to sell it it's just my internal tool so this is what i'm trying to do is to get the installed app so here it is create your own client id and client secret and to do that you need to go to google api console credentials and just follow the steps and if you don't have google api console you need to create one so this is why it's so complicated and after you follow the steps you're going to have this dialog with your client id and your client secret being available you need to copy these two things and then paste them here into client id and client secret but also you will need them once more because you don't have refresh token and this is another thing that you need to have and to generate the refresh talking we go a bit further and there is a configure and use a client library we click on python and then again i use installed app flow which by the way i think yeah it is the same way so we have this file we have this page uh on a gitlab and this is another guide on how to use client id and client secret and the get refresh token to do that what you need to do is to download this file adwords generate refresh token dot py copy this copy paste this which i guess is just okay i don't remember is the copy i i usually work with the gitlab so nonetheless just copy all the stuff uh paste it in your python folder and run it so i'm gonna do right here new file and then refresh token dot py i don't want to add it to version control and then i paste it here i get this way and all i need to do is to add here the font client id and then default client secret so the same things i put inside here default client id and client secret paste it here run the script and this script should return me uh sorry wait a second i lost the page and this page this ticket this script will launch the web page that will ask you for permission then copy the some temporary token paste it back to the terminal which by the way if you don't know is here and you will see it when you run the script and then you will have your code and access token refresh token and this is the refresh token you need to have and need to copy paste as output of your script inside the google ads public here so i can just try to replicate this for you so we are on the same page so here on the script uh i have this link i need to click on it and the script awaits for the code that will happen here so i log in to my account i allow manage your adwords campaigns by the way they forgot to rename it here uh then i do allow again copy paste the code come back here uh paste it push enter and here i have my access token and my refresh talking right away okay so i've updated refresh talking in my main google ads yaml which i definitely cut it from this video and uh i also don't worry i updated all the tokens here so you there is nothing uh you can actually see and this is important thing i totally forgot about to say about this is like anything anything and all at all in this file should be private and you should never ever share it with anybody else this is your complete this is a complete access to google ads with the api so be careful so after you fill that file uh you can run the google ad scripts and to do that to actually run it what you need to have is you need to have um let's go back this is an example by the way which i took sorry for like chopping here and there i just want to show you everything so this is close to the right oh this is so complicated so let me just do this okay this is the page on the library page there is an examples folder here and you can copy any script here if you want at all so i can just um let's go to reporting uh let's go get keyword stats and there is a main function the very end if name equals main and this is the code that's going to be run first so what they do here they create google ads client equals google ads client class dot load from storage and this will load your credentials from your java file then they do some checks uh in case you run it from the um terminal which i'm not interested in and then they just run the main function and they pass google ads client which is here and they uh pass the customer id so let's come back and see how i've done it so this is the google ads keywords keywords reporting file so yeah here i have exactly the same copy paste so no need to worry about that so i have if name equals name and i do not run it from terminal i don't need this parse args and this is kind of stuff i just run the main function with the google ads client and with the id of some existing client inside my mcc so to make it work you need to create this google ads client and the problem is that usually when they do load from storage you very often they have a mistake or error or something else that there is it's very difficult to find credentials so what i did on the very top again on the inside the rc file which is the source file source code files for my project i created a file called init dot py underscore underscore you need underscore underscore dot py and i just created a small script that will always be needed for all the files inside this project so i create a new path that will identify where exactly my local territory is right now then i create a credential dictionary potentials dictionary that contains a key sorry uh google ads and then it contains my local directory and inside it i have the creds folder and inside it i have google google ads.yaml file which is here and then what i do i also copy paste the login information this is something from the tutorial they have themselves so you just need to copy paste that and the very end i do from google ads from google.ads.googleads.client import google ads client and i create this google ads client each time i run the app the beauty of it is that i don't need to think about low reload from storage on where the file is located anything else all i do is google ads client equals this a lot from storage and then credentials google ads so it takes this address from credentials file and it creates the google ads client for me that i can just import and this is exactly what i do inside the script in the very beginning i have a line that says uh where it is by the way here from source from main folder import google ads client and then pass it in the main function and as easy as that uh just spending if you maybe spending half an hour on this video and then spending a few weeks on making it all work this script actually runs which is an amazing success but to be honest guys to be actually honest is google ads api is not simple is not easy to master but it has a huge potential for those that manage campaigns themselves for small agencies from for freelancers and for marketing analysts that wanted to succeed in this area and the thing is the reason why it's happening this way is because you have an enormous potential of updating millions and thousands of keywords very easily compared to ads editor when you have to download everything locally which sometimes takes hours or to user interface which is far from being perfect and google ad scripts only have a limitation to 50 000 keywords in most of the cases so besides the fact that it's javascript so all in all google ads scripts uh sorry all in all python api is an amazing tool to master but you need to take to take into account that it will take some time to actually do that and the same for me i don't have any ideas so far what i'm gonna build uh right away what's gonna be my next step here uh if you have any script or any question or anything that you would like to see building inside the my project you're very very welcome to write this in a comment and of course if you have any problem with automation google ads scripts python or anything in general relating to marketing analytics just write me on the linkedin and we probably will find something uh together that will solve the problem or maybe work together thank you very much subscribe to this channel leave your comments and push a very big like because it took me a lot of time to make this video uh thanks say thank you very much for staying and i will make sure i will make another video soon bye bye guys
Info
Channel: Marketing Watch House
Views: 49,244
Rating: undefined out of 5
Keywords: google ads api, google adwords api, google ads python, google ads token, google ads automation, google ads tutorial, google ads lib, google ads yaml, yaml api file, google ads developer token, google ads client id, google ads client secret, google ads refresh token, adwords reports, google ads api reports, google ads api python, google ads api python tutorial, google ads api setup, google ads api discovery campaigns, google adwords api tutorial, adwords api success story
Id: cKODT6-u_bA
Channel Id: undefined
Length: 22min 40sec (1360 seconds)
Published: Sat Dec 19 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.