Setup Guide
This guide walks you through creating a Google Cloud Platform project, enabling the Google Sheets API, and obtaining the OAuth 2.0 credentials required to use the Google Sheets connector.
Prerequisites
- A Google account. If you do not have one, sign up here.
- Access to the Google Cloud Platform Console.
Step 1: Create a Google cloud platform project
- Open the Google Cloud Platform Console.
- Click Select a project in the top navigation bar and either select an existing project or click New Project.
- Give your project a name (e.g.,
Ballerina Sheets Integration) and click Create.
Step 2: Enable the Google sheets API
- In the GCP Console, select your project.
- Navigate to APIs & Services > Library.
- Search for
Google Sheets APIand select it. - Click Enable.
Step 3: Configure the OAuth consent screen
- In the left sidebar, navigate to APIs & Services > OAuth consent screen.
- Select External as the user type and click Create.
- Fill in the required app information (App name, User support email, Developer contact email).
- Add the necessary scopes for Google Sheets API (e.g.,
https://www.googleapis.com/auth/spreadsheets). - Save and continue through the remaining steps.
Step 4: Create OAuth client credentials
- In the left sidebar, click Credentials.
- Click + CREATE CREDENTIALS and choose OAuth client ID.
- Set Application type to Web application.
- Enter a name (e.g.,
Ballerina Sheets Client). - Under Authorized redirect URIs, add
https://developers.google.com/oauthplayground. - Click Create.
- Copy the Client ID and Client Secret from the confirmation dialog.
tip
Store the Client ID and Client Secret securely. Do not commit them to source control. Use Ballerina's configurable feature and a Config.toml file to supply them at runtime.
Step 5: Obtain access and refresh tokens
Use the Google OAuth 2.0 Playground to generate tokens:
- Open the OAuth 2.0 Playground.
- Click the gear icon (settings) in the top-right corner and check Use your own OAuth credentials.
- Enter your Client ID and Client Secret.
- In the left panel, find and select the Google Sheets API v4 scopes (e.g.,
https://www.googleapis.com/auth/spreadsheets). - Click Authorize APIs and sign in with your Google account.
- Click Exchange authorization code for tokens.
- Copy the Refresh Token from the response.
note
The access token expires after a short period. The refresh token is used by the connector to automatically obtain new access tokens, so make sure to save the refresh token.