How to create Service Account and enable Google Cloud API

To work with Google’s API, we must create a Service Account in the Google Cloud Platform and download a JSON file containing account information. After creating the account, we need to enable Google Cloud API to use the Service Account in Python programming and applications. Follow the instructions in this article to help you reach the fastest.

What is Service Account?

A service Account is a particular type of account often used to call APIs in applications and programming. This account is authorized as the primary account of the user of the Google service. It can do many things for you, many operations with Google products that you are using.

PasswordNo, it can’t log in with a browser or cookies.
AccuracyNot for authentication, only public/private RSA key pairs.
AuthorityIt can authorize as a user account.
Google WorkspaceThey are not counted when sharing assets in Google Workspace.

Create Service Account

Step 1: You need to create a Project to contain one or more Service Accounts. Try going to console.cloud.google.com/projectcreate to create a new Project.

Create a Project before creating Service Account
Create a Project before creating Service Account

Step 2: You fill in the essential information to create a Project. Note that the Project ID will be fixed and cannot be changed later. If you don’t have any location, leave No organization.

Fill in the information to create a Project
Fill in the information to create a Project

Step 3: After creating a Project, select the exact Project that you want to use to create the Service Account.

Choose your Project
Choose your Project

Step 4: Access the Service Account management page by clicking IAM & Admin > Service Accounts.

Access the Service Account management page
Access the Service Account management page

Step 5: Click the Create Service Account button to create an account.

Click Create Service Account to create a Google service account
Click Create Service Account to create a Google service account

Step 6: Fill in the information to create Service Account. Note that you should keep the Service account ID short and friendly because it will generate an email address you can use later. You can grant Owner rights to this account or not grant them later, which does not affect the use of APIs.

Fill in the information to create Service Account
Fill in the information to create Service Account

Step 7: Try accessing Manage keys for your Service Account by clicking the options button. This is the step to create a JSON file containing the account information.

Access to Manage Keys
Access to Manage Keys

Step 8: Click Add Key and select Create new key to generate a private key.

Generate a Private key for your Service Account
Generate a Private key for your Service Account

Step 9: Select JSON and click Create to create a JSON file for your Service Account.

Select JSON and click the Create button
Select JSON and click the Create button

Step 10: Your browser will immediately download the JSON file to your computer. Click the Close button to finish.

After the JSON file is downloaded, it is complete
After the JSON file is downloaded, it is complete

And the wire is the example content in the JSON file containing the access information to your Service Account account. Please keep it safe, and only share it with people you trust. Using Python, you can create a dictionary variable with the same content in this JSON file to work with Google’s API.

The content in the JSON file contains your Service Account access information
The content in the JSON file contains your Service Account access information

Enable Google Cloud API

Once you’ve created a Service Account, you must enable the necessary APIs to work with your API calls.

Step 1: Access the Google Cloud API library by clicking APIs & Services > Library.

Go to the library to enable the Google Cloud API
Go to the library to enable the Google Cloud API

Step 2: Search for the APIs you want to use. The function of each API is specified below the description. Lucid Gen will show you some famous API examples below.

  • Google Drive API will help you create files, manage file sharing, and search files and folders.
  • Google Sheet API will help you edit the content and get the content of the worksheets.
Find the APIs you want to use in Google Cloud Library
Find the APIs you want to use in Google Cloud Library

Bước 3: Bật API mà bạn đã chọn.

Enable Google Cloud API
Enable Google Cloud API

Step 4: View the overview of the data you used with the API. You can disable an API by clicking the Disable API button.

You can disable the API in the dashboard
You can disable the API in the dashboard

Finally, depending on the API use case, you may have to share editing permissions for this Service Account. For example, Google Drive or Google Sheets. This Service Account’s email is the client_email in the JSON file on your computer.

Share editing permissions for Service Account's email client
Share editing permissions for Service Account’s email client

Frequently asked questions

Why is the API enabled but still getting an error when calling the API?

Some APIs require you to share editing permissions with the client email to work. Check if you have shared permissions for the Service Account client email.

What should I do when I lose the Service Account JSON file?

You cannot request a re-issue of the JSON file containing the Private key of the created Service Account. But you can delete the old key and create a new one.

Conclusion

Lucid Gen hopes this article will help you quickly and effectively create a Google service account quickly and effectively. I am also learning and working with Google Cloud, hope to have many experiences to share with you in the future. Please leave a message below the comment section to ask questions or chat with me.

Related articles

Hieu Tran Ngoc Minh

Hieu Tran Ngoc Minh

I am currently working as a Data Analyst; before that, I worked in Digital Marketing. Blogging is a joy, helping me share my knowledge and experiences from life and work. You can donate to me here.

Leave a Comment

Feel free to leave your comment, and we will review and respond as soon as possible. Please use a real email to ensure your comment is approved and to receive notifications when we reply. You can also add an avatar to your email.