Google Cloud AI Services Quick Start Guide
上QQ阅读APP看书,第一时间看更新

Setting up service account key

Now that we have a project and an API key, let's set up a Service Account Key as well.
Follow these steps:

  1. Navigate to Google Platform Console: https://console.cloud.google.com/
  2. Select the project we have created
  3. From the menu on the left-hand side, select APIs & Services
  4. Once you are on APIs & Services page, from the menu on the left-hand side, select Credentials
  5. Using the Create Credentials dropdown on the page, select Service account key
  6. Under Service account dropdown, select New service account and fill it as below
    1. Service account namesmart-exchange-service-account
    2. RoleProjectOwner (do not use this role in production, provide access to only the required services)
  7. Leave the auto generated Service account ID as is
  8. Under key type, select JSON
  9. Click on Create and you should be prompted to download a JSON file.
  10. Download and save this file securely and protect it as you would a secure password.

We will be using a service account key when we make a service call from our application
using the SDK. The SDK expects this JSON file's path to be exposed using a environment
variable named GOOGLE_APPLICATION_CREDENTIALS and the value as the path to the
JSON file. If you are using an *nix-based OS, you can set this value from the Command
Prompt as follows:

export GOOGLE_APPLICATION_CREDENTIALS=/Users/arvindravulavaru/Downloads/ SmartExchange-29e9aed0a8aa.json

Or you can add the same to bashrc or profile or zshrc file.

On Windows, you can use:

setx GOOGLE_APPLICATION_CREDENTIALS "C:/Users/arvindravulavaru/Downloads/ SmartExchange-29e9aed0a8aa.json"

For more help on setting environment variables, refer: https://www.schrodinger.com/kb/1842. We will be using this later on when we are integrating the API with our application.