> ## Documentation Index
> Fetch the complete documentation index at: https://docs.useparagon.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Drive

## Required Scopes

To configure a Sync for Google Drive, you need to request the following scopes from your Google OAuth application:

* `https://www.googleapis.com/auth/drive.readonly`

  <Info>
    If you are syncing only user-selected files, you can request the less permissive `https://www.googleapis.com/auth/drive.file` scope.

    This will restrict the sync to only files that the user has selected with the [Google Drive File Picker](#choosing-files-and-folders).
  </Info>
* `https://www.googleapis.com/auth/admin.reports.audit.readonly` (optional - for including link-sharing access in the Permissions Sync)
* `https://www.googleapis.com/auth/admin.directory.group.readonly` (optional - for including group membership in the Permissions Sync)

Learn more about configuring scopes for your app in [Adding Integrations](/getting-started/adding-an-integration#create-a-developer-app).

## Synced Objects

Google Drive supports the following Synced Objects:

* [Files](/managed-sync/api/file-schema)
  <p>Google Docs, Sheets, and Slides will be synced as their Office-compatible equivalent formats:</p>
  * **Docs**: DOCX file
  * **Sheets**: XLSX file
  * **Slides**: PPTX file
  * **Drawings**: PDF file
* [Permissions](/managed-sync/permissions-api)

## Files

Send a request to [Enable Sync](/managed-sync/api/enable-a-sync) to start a file sync.

Syncs for Google Drive can be created with one of the following configurations:

* **Global Sync**: All files in the user's Google Drive account will be synced.
* **Folder Sync**: Only files in the specified folder will be synced (recursively including all subfolders by default).
* **Sync of specific files**: Only a group of specific files will be synced.

<Tabs>
  <Tab title="Global Sync">
    ```json Example theme={null}
    {
        "integration": "googledrive",
        "pipeline": "files",
        "configuration": {}
    }
    ```

    **Configuration options:**

    <ParamField path="mimeTypes" type="string[]">
      An optional array of MIME types to filter synced files. Only files matching the specified MIME types will be synced.
    </ParamField>
  </Tab>

  <Tab title="Folder Sync">
    ```json Example theme={null}
    {
        "integration": "googledrive",
        "pipeline": "files",
        "configuration": {
            "folderId": "1DBmDMhWTzNapG2sSiu7-u7lkSCJnyC34"
        }
    }
    ```

    **Configuration options:**

    <ParamField path="folderId" type="string" required>
      A Google Drive Folder ID to limit the Sync scope to.
    </ParamField>

    <ParamField path="shallowSync" type="boolean">
      Set to `true` to sync only the direct children of the specified folder, without recursing into subfolders. Defaults to `false`.
    </ParamField>

    <ParamField path="mimeTypes" type="string[]">
      An optional array of MIME types to filter synced files. Only files matching the specified MIME types will be synced.
    </ParamField>
  </Tab>

  <Tab title="Sync of specific files">
    ```json Example theme={null}
    {
        "integration": "googledrive",
        "pipeline": "files",
        "configuration": {
            "fileIds": ["1DBmDMhWTzNapG2sSiu7-u7lkSCJnyC34"]
        }
    }
    ```

    **Configuration options:**

    <ParamField path="fileIds" type="string[]" required>
      A list of Google Drive File IDs to limit the Sync scope to.
    </ParamField>

    <ParamField path="mimeTypes" type="string[]">
      An optional array of MIME types to filter synced files. Only files matching the specified MIME types will be synced.
    </ParamField>
  </Tab>
</Tabs>

## Choosing Files and Folders

You can allow your user to select files from their Google Drive account in your app with the Google Drive File Picker provided by the Paragon SDK.

<Frame>
  <img src="https://mintcdn.com/paragon/DkcdqxlytLXlO_-w/assets/CleanShot%202023-10-18%20at%2011.47.47.gif?s=1c26d528047021aa50ac518d4eab10c8" alt="" width="563" data-path="assets/CleanShot 2023-10-18 at 11.47.47.gif" />
</Frame>

**Enable the Google Picker API**

You will need to enable the Google Picker API for your application in order to access the File Picker.

1. In your [Google Cloud Console dashboard,](https://console.cloud.google.com/projectselector2/home/dashboard?supportedpurview=project) navigate to **APIs & Services > Library** in the sidebar for your app.

2. Search for "**Google Picker API**" from the API Library.

3. Select the "**Google Picker API**" and press the blue "**Enable**" button to enable the API for your application.

<Frame>
  <img src="https://mintcdn.com/paragon/jCM_Y_j0HttScr1R/assets/Enabling%20the%20Google%20Picker%20API%20for%20a%20Google%20Drive%20integraiton%20for%20Paragon%20Connect.png?fit=max&auto=format&n=jCM_Y_j0HttScr1R&q=85&s=e01db9255a3a68ae699a37be6d8608f7" alt="" width="1384" height="506" data-path="assets/Enabling the Google Picker API for a Google Drive integraiton for Paragon Connect.png" />
</Frame>

**Creating a Google Drive API Key**

To show the Google Drive File Picker, you will need a **Google Drive API Key**. This key is a separate key from the Client ID you provided to Paragon during integration setup.

1. Navigate to [Google Cloud Console > APIs & Services > Credentials](https://console.cloud.google.com/apis/credentials). Make sure the selected project in the header is your app.

2. Click **Create Credentials** and select **API key**.

3. An API key value will appear. Copy this value to use in [Showing the File Picker](#showing-the-file-picker).

<Frame>
  <img src="https://mintcdn.com/paragon/p_CuCy_equ6Xxvlm/assets/credentials_APIs_Services_example_Google_Cloud_console.png?fit=max&auto=format&n=p_CuCy_equ6Xxvlm&q=85&s=7984f759b1623faaa563ca1a712a99e7" alt="" width="2304" height="804" data-path="assets/credentials_APIs_Services_example_Google_Cloud_console.png" />
</Frame>

**Note**: While the API Key value is not sensitive and can safely be used in your public application, we recommend restricting the API Key with the following settings:

* Application restrictions: Websites with your origin/domain
* API restrictions: Google Drive API

[Read more](https://cloud.google.com/docs/authentication/api-keys#api_key_restrictions) in Google's docs for API Key restrictions.

#### Showing the File Picker

Use the Paragon SDK in your frontend application to show the File Picker in your app.

The SDK provides an `ExternalFilePicker` class to load Google's JavaScript into your page and authenticate with your user's connected Google Drive account.

To initialize the picker you will need your Google Drive API key and your Google Cloud project number. The Google Cloud project number is a unique, numerical identifier for your project. You can find it within the Google Cloud Console from the sidebar navigation under [**IAM & Admin section > Settings**](https://console.cloud.google.com/iam-admin/settings).

```js theme={null}
let picker = new paragon.ExternalFilePicker("googledrive", {
    onFileSelect: (files) => {
        // Handle file selection
    },

    // Optional settings:
    integrationOptions: {
        googledrive: {
            // If true, a tab in the Picker appears for browsing Shared Drives
            enableSharedDrives: true,

            // If true, the full folder hierarchy appears in the Picker. Otherwise,
            // all files will appear as a flat list. Defaults to `false`.
            includeFolders: false

            // Set the display mode of the Picker as a thumbnail grid or list of file titles.
            // Defaults to "grid". Thumbnail grid requires either `https://www.googleapis.com/auth/drive` or
            // `https://www.googleapis.com/auth/drive.readonly` scope to appear correctly.
            viewMode: "grid" || "list",
        }
    }
});

// Loads external dependencies and user's access token
await picker.init({ developerKey: "YOUR_GOOGLE_API_KEY", "appId": "YOUR_GOOGLE_PROJECT_NUMBER" });

// Open the File Picker
picker.open();
```

You can configure the File Picker to listen for additional callbacks or to restrict allowed file types. Learn more about configuring File Picker options in the [SDK Reference](/apis/api-reference#externalfilepicker).
