How To Build Your Own Keyword Tool With Google Ads API & C#
Tags: csharp, opensource, dotnet, googleapi
Published: 2022-06-22 19:06:52

## What we will build?

We'll use Google Ads API to build a keyword Research tool that allows you to get keyword suggestions and metrics like **Search volume data** , **CPC** and **Competition** based on user input.

## Examples of keyword tools:

If you go to **keywordtool.io**, you can search for a keyword, it will give you hundreds of keyword suggestions.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3mrhxmkex5qmneqx0puz.PNG)


_**It is considered one of the best free keyword tools. (But it’s not totally Free)**_

Another example is **H-supertools**. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u0wta8v9eln4phfybggu.png)

I developed H-supertools from scratch, and today this website is one of my main income streams. 

Today, In this post, I will reveal how you can build similar tools, so maybe you can turn it also into an income source too! 



## How does our Keyword Tool works?
It's a simple C# console application. When you run it, you'll have two options:

1. Authenticate with Google Ads API
2. Perform keyword research


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q4nxco1qhbtjrk4d4u64.png)

Let's perform Keyword Research and search for "C#"
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u0ryb96h8ektksir1tww.png)

After the search, our tool gets back ~500 keyword ideas with search volume data, competition, and CPC values. 

_Of course, In my case, it's a simple console application (just for simplicity reasons) But we can use and implement the same code in any type of applications like mobile, web, or even a desktop application._


## Let's Start Coding!

**Step 1: Setup Your Google Console Account**

So, our first step is to go to [Google cloud console](https://console.cloud.google.com/) and login with your Gmail account.

After you login, **create a project**, and then **click on Enable APIs**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sp8sghd9q8jlc7es76ul.png)

Now search for “Google ad API” and **Enable The API** 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bf4kulpgj9xvy67ska1j.png)



**Step 2: Create OAuth Credentials to access Google Ads API**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oxz8tr82xkmc4jphpm5b.png)

Finish the wizard, then you will be able to get the client and secret IDs as shown in the images below:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/frwxcq9h0a6te5nbsaeh.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z0lag90opczu7oswb5u5.png)

**We will use these Keys to authenticate our application.**
 
Before we continue, if you are that person who loves to watch videos instead of reading long posts, you can check the full tutorial here:

{% embed https://youtu.be/UCnpa2-s9h4 %}


## Google Ads API Authentication Code

Open _**KeywordIdeasGoogleAPI.cs**_ Class in our Project.

![google ads api with c#](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ght9te5lkxm2t39ritfr.png)

You will see we have two methods.

- Authenticate()
- Search()

I found the Google ads API authentication code on [Github](https://developers.google.com/google-ads/api/docs/samples/).
 
I tweaked it a little bit and Made it simpler for you to understand and use 😃


**Let's Authenticate!**

I will run the application.

![google ads api authentication c#](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mb64x0a3giayr9hpyu5w.png)

Hit 1 to authenticate.

It will ask you for the client ID and secret

![google ads api authentication example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n14cf1j8dror9ma0ushf.png)

Copy From Google Console, Paste, hit enter, and authenticate your Gmail account.

Now it will prompt you to copy authentication keys:

![google ads api c# authentication keys](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zdd789gi247aakkmyjl9.png)

Copy and paste these keys in the app.config file in your project files.

![google ads api app.config](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tff1664nrvedidwjbnxo.png)


## How To Get The Google Ads Developer Token

Now the next step is to get the developer token. As You can see, we need to set the developer token in the app.config file.

For this, you will need to create a _Google ads Manager Account_.

![Google ads Manager Account](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fagkjs8znn7781b85eb6.png)

[Click Here To Create a Google ads Manager Account.
](https://developers.google.com/google-ads/api/docs/first-call/dev-token) 


Create one, Sign In, and click on **tools**, then click on **API center** and you'll see the developer token there.

![google ads developer token](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nn1zqity6u0sctpmafye.png)
 
We got the Token, Paste in the app.config file, and we are ready!


## Perform a Keyword Research Test

In the Google Ads API, we have the [keyword ideas service](https://developers.google.com/google-ads/api/docs/keyword-planning/generate-keyword-ideas).

It is the service I used to perform keyword research.

The Sample Code mentioned on the page will not work directly, this is why again, I tweaked and simplified it so you can run easily and smoothly. **(I think I deserve a Heart and maybe a Unicorn 😅)**

**The Search Method** 

![Keyword tool with google ads api](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wzgkkvrbzkuvrm0ndav1.png)
 
In the main application, create an instance of our class **_KeywordIdeasGoogleAPI_**.

Create a new object of Google client, and pass it to the search method with other parms: _locationId_, _customerId_, _languageId_, and the _searchTerm_.

![keyword tool with google ads api](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/it0sdsu6y0m2n445sanl.png)
 

**How to get the customer id?**
[Create a Google Ads Test Account
](https://developers.google.com/google-ads/api/docs/first-call/test-accounts) 

Login, and you will see a red message showing that this is a test account, just click and copy the customer ID as shown below:

![google ads test account](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yz6ttbtkfpi3yra0gojm.png)

Make sure to remove the dashes and keep only the numbers when you paste in your code.
 
we still have locationId and languageId.

Find a list of Location IDs by [clicking here](https://developers.google.com/google-ads/api/reference/data/geotargets). And Find a list of Language Ids [here](https://developers.google.com/google-ads/api/reference/data/codes-formats#languages).

For Example, "_English_" Id is **1000**, and "_New York_" Id is **21167**.

**Now we are ready to perform a keyword research!**

Run the application again

![keyword tool with c#](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ugk7iyvp672dewtgi0jq.png)

Let's say, we wanna search for this keyword: “[subscribe to my channel.](https://www.youtube.com/channel/UCiLmLn593TxhOLpvbOfJFRg)” 😅

Hit Enter, and you will see the Magic🎩

![get search volume with c#](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/274yr7lg6d1fqewyajb5.png)

_**Note: CPC Bids means that advertisers are paying these numbers to advertise on Google.**_


[Check The Full Project Here on Github.
](https://github.com/hassancs91/Keyword-Research-Tool-Google-Ads-API-Csharp)

If you did it. Congratulations 🥳

The Google Ads API is free but has some limitations.Did you know you can use the [Free Google Suggestions API](https://dev.to/hassancs91/develop-a-keyword-research-tool-in-minutes-python-and-c-4g32) To Develop a Keyword Research Tool with no limits! Yes! If you wanna learn how. Check this [post](https://dev.to/hassancs91/develop-a-keyword-research-tool-in-minutes-python-and-c-4g32).