上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:
- Navigate to Google Platform Console: https://console.cloud.google.com/
- Select the project we have created
- From the menu on the left-hand side, select APIs & Services
- Once you are on APIs & Services page, from the menu on the left-hand side, select Credentials
- Using the Create Credentials dropdown on the page, select Service account key
- Under Service account dropdown, select New service account and fill it as below
- Service account name: smart-exchange-service-account
- Role: Project| Owner (do not use this role in production, provide access to only the required services)
- Leave the auto generated Service account ID as is
- Under key type, select JSON
- Click on Create and you should be prompted to download a JSON file.
- 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.