The following example shows several important steps to call Google Cloud APIs without using an SDK in Python. Similar code works in just about any language (c#, java, php, nodejs).

Change the source code with the filename of your service account Json file, your Google Zone and your Project ID.

This example will list the instances in one zone for the specified project. From this example you will know the framework to call almost any Google Cloud API.

This code will show you how to:

  1. How to load service account credentials from a Json file.
  2. How to extract the Private Key used to sign requests.
  3. How to create a JWT (Json Web Token) for Google Oauth 2.0.
  4. How to set the Google Scopes (permissions).
  5. How to sign a JWT to create a Signed-JWT (JWS).
  6. How to exchange the Signed-JWT for a Google OAuth 2.0 Access Token.
  7. How to set the expiration time. This program defaults to 3600 seconds (1 Hour).
  8. How to call a Google API and set the Authorization Header.
  9. How to process the returned Json results and display the name of each instance.

Example program in Python 3.x: