How to create credentials for commonly used Google APIs

How to create credentials for commonly used Google APIs

Google lets you access all its powerful services by providing an API for each one:

  1. Places API (Premium)- Provides detailed information about places (e.g., businesses, landmarks).
  2. Custom Search API — Enables developers to add web search and site search capabilities to their websites or create SEO tools
  3. PageSpeed Insights API — For accessing website performance metrics
  4. Business Performance API — For accessing data related to Google My Business.
  5. YouTube API — Enables apps to access YouTube content (upload videos, manage playlists, retrieve video info).
  6. Gmail API — Provides RESTful access to Gmail mailboxes, letting apps read, send, and manage emails on behalf of users.
  7. The list goes on and on

But the problem is, it is not straightforward to generate API credentials for the above services of Google.

We have to follow a specific process to be able to create API credentials.

The process is usually spanned into four steps:

  1. Create a Google account
  2. Access the Google Cloud Platform dashboard
  3. Select a project
  4. Enable APIs you want to work with
  5. Create credentials for an API and restrict them to used only with certain APIs you have enabled

If you are trying to access a premium APs like Places API, you should also add a payment method and verify it as an additional step.

Ufff…long process if you're going through this for the first time.

But you have to start somewhere, right?

And this article is all about that.

Come on, let's generate some API credentials.

Step 1: Create a Google Account

It doesn't matter to what API you are generating credentials for.

It is mandatory for you to have a Google account if you want to generate API credentials for any Google service.

If you have a Gmail account, you technically have a Google account too.

So, If you already have a Gmail account, skip this step.

But if you don't have an account, go to:

https://accounts.google.com/

And then click on the “Create Account” button to create an account by entering your personal details:

Create Account on Google sign in page

Once you are done, you'll be redirected to the Welcome screen of your Google Account:

Welcome screen after creating a Google account

When you created your Google account using a particular email, Google has automatically created accounts for you on:

  1. Gmail
  2. Google Drive
  3. Google Cloud Platform — Allows you to create API credentials for all Google services
  4. The list is big

This means, you can access the above services without creating a new account on them.

Anyway, our next step is to access Google Cloud Platform, right?

So…

Step 2: Access the Google Cloud Platform(GCP) dashboard

If you're hearing about GCP for the first time, think of it as a big set of online tools and services offered by Google.

Think of it as a giant toolbox in the internet cloud, where developers and businesses can rent and use different computing resources without needing to own and manage their own physical computers.

And one of the important things you can do with GCP is to create credentials to securely access various Google API services using automation tools like Make.com.

Anyway, now that you understand the purpose of GCP, it is time to access it and create a new project inside it.

You can directly access GCP by going to:

https://console.cloud.google.com/

Next, if you're accessing the Google Cloud Platform for the first time, you'll be asked to agree to their terms of service:

Go through the terms of service and if you're okay with it, Agree and continue.

Next…

Step 3: Select a project

When we generate API credentials inside GCP, we must assign them to a particular project.

So, we must create a new project and then generate API credentials using it.

To achieve this, first click on the “Select Project” button located on the top-left side of the screen:

Select project on GCP

And then click on “New Project”:

Create new project on Google Cloud Platform

Next, enter a recognizable project name like “Task Automation” and create the project.

Enter the details of new GCP project and create it

Once the project is created, click on the “Select Project” button once again:

Select project on GCP

And then select “Task Automation” project from the list:

Select the newly created project

That's all.

We have now set up the foundations for creating credentials for any Google Service.

Step 4: Enable APIs you want to work with

To be able to send requests to a particular Google service, we should first enable the API access for that particular service.

To do so, click on the navigation menu icon located on the top-left-hand corner of the screen:

Button for accessing the navigation menu of GCP

And then go to:

APIs & Services → Library
The Library of APIs you can enable on GCP

This will take you to the Google API Library, where you can search and enable any Google API you want.

Google API Library search box

For example, I want to use PageSpeed Insights API.

So, I will search for it.

If everything goes well, I should see the “PageSpeed Insights API” card as a search result:

Search results for PageSpeed Insights API

I will then click on the “PageSpeed Insights API” card and then enable it:

Enable PageSpeed Insights API

You can do the same for enabling any service's API.

For example, I have also quickly enabled the YouTube Data API by following the above process:

YouTube API search results
Enable YouTube Data API

Now, if you want to send requests to any Google API, enabling it is not enough.

We should create an API key and then assign it to the respective Google API.

So…

Step 5: How to create credentials for an API and then assign it to specific enabled services

We can create new credentials for an API and restrict them to be used only with certain Google services.

In other words, we can create an API credential and assign it to more than one Google service.

For example, you can reuse the same API credential for authenticating with:

  1. Google Sheets API
  2. PageSpeed Insights API
  3. YouTube API

And here is how you can do it.

First, go to:

APIs & Services → Credentials
Link to the credentials page of GCP

Next, click on the “Create Credentials” button:

Create credentials button on GCP

This will bring up a popup where you can select one of three credential types:

  1. API Key
  2. OAuth Client ID
  3. Service Account
Different types of Credentials we can create

For the purposes of this lesson, let's see how to create API credentials using the API key.

We could also talk about how to generate credentials using OAuth Client Option:

But OAuth client ID configuration changes depending on the app that is sending requests to the Google APIs.

And since this lesson is trying to be universal, I have decided to focus on creating API credentials using the API key.

API keys can be used inside any app in the same way.

So, let's see.

How to create an API Key and then assign it to specific “enabled” APIs

To achieve it, when you click on the “Create credentials” button, choose the “API key”:

Choose API key for the credential type

This will create a new API key:

API key created

Having said that, currently, the newly created API key is unrestricted.

It means, it can be used for accessing the API of any enabled Google service from the API Library.

This is not secure because it could result in unauthorized use.

So, our next step is to restrict the newly created API key to be used with only a few selected services.

Applying restrictions to the API key

To do this, first close the “API key created” dialog box.

Next, click on the newly created “API key 1” to access its “Edit API” screen:

Click on the API key to edit it

Next, under the “API restrictions” section, choose “Restrict key”:

Restrict the key to selected APIs

And then select the APIs that you want to access using this API key:

Select the APIs and Click ok

Once you select them, click the “OK” button and then click on the “Save” button:

Save the API selection

That's all.

You can now use the API key to send requests to selected APIs.

If you try to use the API key for non-selected APIs, the request will get bluntly rejected.

Nice touch of security, right?

Also, you can access the API key anytime by clicking its “Show key” button:

Show API key button

It opens up the dialog box with your API key:

Restricted API Key that is ready to be used

And that's exactly how you create Google Credentials for accessing a particular API.

Now, I might have diverted you here from a different article, if that is the case, go back to it.

We are done here.