Learning Outcomes
- To learn the appropriate steps for setting up a Google Cloud Platform project.
- To learn how to activate specific APIs which can then be accessed via a Service Account.
- To learn the importance of hiding your .json service account keys from the internet.
This will be a short guide on how you can get started as quickly as possible using Google Cloud Platform with some of Google’s APIs.
Step 1 – Setup A Google Cloud Platform Account
Firstly you will need to correctly register for a Google Cloud Platform account, you’ll likely be able to use your existing Google account.
Step 2 – Activate Billing
After successfully registering for a trial account you will be entitled to ~$300 free credits that you can spend within the Google Cloud Platform (GCP). However I’d recommend taking the time now to setup billing by adding a valid credit / debit card.
You can create a Billing Account here and its worthing remembering that one billing account can be used across multiple GCP projects.
Step 3 – Create A Google Cloud Platform Project
Similarly to Google Ads campaigns, there is a hierarchy to how your Google Cloud Account is structured:
Therefore whenever you create a new project, you will need to perform the following:
- Link your active billing account to the project.
- Activate the relevant resources (BigQuery, App Engine, Cloud Storage) etc.
- Turn on the relevant APIs (Google Search Console, Google Analytics) etc.
Step 4 – Create A New GCP Project
You can create a new google cloud project here or alternatively navigate to it within the UI, then click Create Project in the top right corner.
For this tutorial we’ll be creating a new project called Google Sheets API:
Step 5 – Select The Newly Created Google Cloud Project
When adding resources and API’s its vital that you double check to make sure that you’ve selected the correct GCP project.
Step 6 – Turn On The Relevant Resources And API’s For Your Project
As we’ll be using Google Sheets within the next lesson, let’s navigate to the API section and turn on that specific API for this new project.
Step 7 – Authentication With A Service Account
Now that we’ve got the google sheets API turned on, let’s create a service account so that you can programmatically access the resources of your google cloud project.
Create A Service Account
Name Your Service Account
Give Your Service Account Ownership + Programmatic Access
In the example below, I have given my service account admin level access to Google Cloud Functions:
Create a JSON Key
Creating a .json key will allow you to easily interact with your Google Cloud Project using Python. So let’s create and download the .json file:
Okay great so you should have just downloaded a .json service_account key!
If you’re following along from the Python For SEO Course, please can you do the following so that the next tutorials will work:
- Rename your some_name.json key to service_account.json
- Move the .json key into the root directory of this folder: 5_google_sheets_with_pandas
Protip: You must keep your .json key safe and away from the internet. It gives anyone that accesses complete control over that Google Cloud Project.
If you have forked my Github repository then please create a .gitignore file and remove the service-account.json key from your own repository!
Alternatively, please keep the .json key outside of the repository and reference it throughout the course. (This is only a problem for forked/cloned Github repos and if you are just git pulling but not git pushing then there is nothing to worry about here).
Now that we’ve got a .json key with the google sheets api activated we can now move on to reading and writing data from a live google sheet, see you in the next episode!