# How to connect Google Sheets

There are three ways to connect Google Sheets to Connecto: through the Connecto app, through your company's own OAuth app, or through a service account.

## Which one to choose

To reach your spreadsheets, Connecto needs your authorization on Google. That authorization is requested by an app registered in Google Cloud, the OAuth app. The first two options differ in whose app it is.

- **Connecto app.** The app belongs to Connecto. You sign in with your Google account and authorize access to your spreadsheets and your Drive files. Nothing to create.
- **Your own OAuth app.** The app belongs to your company, created in Google Cloud. Use it when the company requires its own credentials or when your Google Workspace admin blocks outside apps.
- **Service account.** A technical Google Cloud account that no person signs in to. It reaches only the spreadsheets shared with it and does not depend on whoever created it.

## With the Connecto app

1. In Connecto, open **Connections** and click **New Connection**.
2. Choose **Google Sheets**.
3. Under **How to connect**, keep **Connecto App** selected.
4. Click **Continue with Google Sheets** and sign in with the Google account that can open the spreadsheets.
5. On Google's screen, tick every permission box and confirm. An unticked box makes the actions that need it fail.

## With your own OAuth app

You need access to the [Google Cloud Console](https://console.cloud.google.com/).

### 1. Copy the redirect URL

1. In Connecto, open **Connections**, click **New Connection** and choose **Google Sheets**.
2. Under **How to connect**, select **Your own OAuth app**.
3. Copy the **Redirect URL** and keep the window open.

### 2. Enable the APIs

1. In the Google Cloud Console, create a project or pick an existing one.
2. In **APIs & Services → Library**, enable the **Google Sheets API** and the **Google Drive API**.

### 3. Set up the consent screen

1. Open **Google Auth Platform**. The first time, click **Get Started**.
2. Fill in the app name, the support email and the contact email.
3. Under **Audience**, choose the user type:
   - **Internal**, if your company uses Google Workspace. Only company accounts can authorize, and Google does not ask for verification.
   - **External**, for personal Gmail accounts or other companies. The app starts in testing mode: add the email of each person who will connect under **Test users** (up to 100 people).
4. Under **Data Access**, add these permissions:
   - `https://www.googleapis.com/auth/spreadsheets`
   - `https://www.googleapis.com/auth/drive.readonly`
   - `https://www.googleapis.com/auth/drive`
   - `https://www.googleapis.com/auth/userinfo.email`

### 4. Create the OAuth client

1. Under **Clients**, click **Create Client**, choose **Web application** and give it a name.
2. Under **Authorized redirect URIs**, click **Add URI** and paste the redirect URL.
3. Click **Create** and copy the **Client ID** and the **Client secret**.

> The full Client secret only shows now. If you lose it, add another one to the same client.

### 5. Finish in Connecto

1. In the connection window, paste the **Client ID** and the **Client Secret**.
2. Under **Permissions**, keep all of them selected.
3. Click **Continue with Google Sheets** and authorize, ticking every box.

### Testing mode

For an **External** app in testing mode, the authorization expires after seven days and the connection stops. To avoid this, publish the app under **Audience → Publish app**.

The Drive permissions are restricted, so Google asks for a verification that includes a security assessment. Until then, Google shows a warning before authorization and accepts at most 100 new users. You can confirm the warning and go on.

## With a service account

### 1. Create the account and the key

1. In the Google Cloud Console, enable the **Google Sheets API** and the **Google Drive API** under **APIs & Services → Library**.
2. Under **IAM & Admin → Service Accounts**, click **Create service account**, give it a name and finish.
3. Open the account, go to the **Keys** tab and click **Add key → Create new key → JSON**. The file downloads only once: keep it.

> If Google blocks the key, your organization has the `iam.disableServiceAccountKeyCreation` policy on, as it is by default since May 2024. A Google Cloud admin has to lift it for the project.

### 2. Share the spreadsheets

1. In the JSON file, copy the `client_email` value, which ends in `iam.gserviceaccount.com`.
2. Share each spreadsheet, or their folder, with that email as **Editor**.

### 3. Connect in Connecto

1. In **Connections**, click **New Connection** and choose **Google Sheets**.
2. Under **How to connect**, select **Service Account (Advanced)**.
3. In **Service Account JSON Key**, paste the whole content of the file.
4. Leave **User Email** empty unless you use the delegation below.
5. Click **Save connection**.

### Domain-wide delegation (optional)

In Google Workspace, the service account can act on behalf of a person and see their spreadsheets without sharing them one by one. Only a Workspace super admin can turn this on.

1. In the Google Cloud Console, open the service account and copy the **Client ID** under **Advanced settings**.
2. In the [Admin Console](https://admin.google.com/), go to **Security → Access and data control → API controls → Manage Domain Wide Delegation** and click **Add new**.
3. Paste the Client ID and the four permissions from the consent screen, separated by commas.
4. In Connecto, fill **User Email** with that person's email.

## Common problems

### The connection stopped after seven days

The OAuth app is in testing mode. Publish the app or, if the company uses Google Workspace, switch to **Internal**. Then reconnect.

### `redirect_uri_mismatch` error

The URL under **Authorized redirect URIs** is not identical to Connecto's. Copy it again and paste it with no spaces and no slash at the end.

### `admin_policy_enforced` error

Your Google Workspace admin blocks outside apps. They allow the app in the Admin Console, under **Security → Access and data control → API controls → Manage App Access**, marking it as **Trusted**.

### The API is disabled in the project

Enable the **Google Sheets API** and the **Google Drive API** under **APIs & Services → Library** and try again.

### The spreadsheet does not show up in the list

With a service account, share the spreadsheet with the `client_email`. With an OAuth app, reconnect and tick every permission box.
