# Google Drive (`onidivo/google-drive`) Actor

Transfer files between Apify's key-value stores and Google Drive.

- **URL**: https://apify.com/onidivo/google-drive.md
- **Developed by:** [Onidivo Technologies](https://apify.com/onidivo) (community)
- **Categories:** Automation
- **Stats:** 51 total users, 1 monthly users, 0.0% runs succeeded, 4 bookmarks
- **User rating**: No ratings yet

## Pricing

$20.00/month + usage

To use this Actor, you pay a monthly rental fee to the developer. The rent is subtracted from your prepaid usage every month after the free trial period.You also pay for the Apify platform usage, which gets cheaper the higher Apify subscription plan you have.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#rental-actors

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## Google Drive

Transfer files between [Apify's key-value stores](https://docs.apify.com/storage#key-value-store) and Google Drive.

- [Input](#input)
   
   [- Constants (`constants`)](#Constants)
   
   [- Operations (`operations`)](#Operations)
   
   [- Is setup mode (`isSetupMode`)](#Is-setup-mode)
   
   [- Google OAuth credentials (`googleOAuthCredentials`)](#Google-OAuth-credentials)
   
   


### Input

The input is a JSON object with the following fields.

| Field | Type | Description | Default value | Possible values | Required |
| ----- | ---- | ----------- | ------ | -------- | -------- |
| constants | array | Constants to use in the operations | - | - | false |
| constants[*] | object |  Constant settings | - | - | - |
| constants[name] | string |  Constant name | - | - | true |
| constants[value] | string or Object |  Constant value | - | - | true |
| operations | array | The operations to execute | - | - | false |
| operations[*] | Object |  Operation settings, mainly it contains the **type** and other specific settings  | - | - | - |
| fileUploadTimeoutSecs | number |  Maximum available time (in seconds) used to upload a single file | 120 | - | false |
| fileUploadingMaxConcurrency | number |  Maximum concurrency used for uploading files in parallel | - | - | false |
| isSetupMode | boolean |  Whether yes or no to activate the setup mode  | false | - | false |
| googleOAuthTokensStore | string |  Key-value store where your Google OAuth tokens will be stored so you don't have to authorize every time again  | "google-oauth-tokens" | - | false |
| googleOAuthCredentials | object | Google OAuth credentials  | - | - | false |

#### Constants
 
An array of folder info constants to use by the operations (DRY principle). Each constant is a JSON object composed of two fields: name and value.

##### Constant value as string

Represent the path of the folder

**Example**
```json
{
      "name": "myFolder",
      "value": "my-project/files"
}
````

##### Constant value as object

Provide more folder definition, which can be useful for defining a shared folder.

**Example**

```json
{
      "name": "myFolder",
      "value": {
            "parentFolderId": "GoogleDriveFolderId",
            "path": "files"
      }
}
```

##### Constant usage

We use the constant inside a string with the following format `"constants.[CONSTANT_NAME]"`.

**Example**

```json
  {
      "type": "folders-delete",
      "folder": "constants.myFolder"
  }
```

#### Operations

Operations are the backbone. Each operation is an object and distinguished by the **type** field. The field **type** can have one the following values: **upload**, and **folders-delete**.

For each operation **type** there are specific settings that accompany as explained below:

##### Operation "upload"

Upload files from the key-value stores to a Google Drive folder.

| Field | Type | Description | Default value | Possible values | Required |
| ----- | ---- | ----------- | ------ | -------- | -------- |
| source | object | Represent the file(s) to upload | - | - | true |
| source.idOrName | string | The ID or name of the key-value store  | - | - | true |
| source.forceCloud | boolean | Forcibly use the key-value store from the cloud | false | - | false |
| source.files | array | File(s) to apply the operation on them  |  |  |  |
| source.files\[\*] | object |  File(s) settings | - | - | true |
| source.files\[key] | string |  The key of the file on the key-value store | - | - | true |
| source.files\[name] | string|  The name of upload file on Google Drive | - | - | false |
| source.files\[mimeType] | string |  The Google Drive MIME type of the file | - | [Google Drive MIME types](https://developers.google.com/drive/api/v3/mime-types) | false |
| destination | string / object | Info of the Google Drive's folder where we will upload the file(s) | - | - | true |

**Example**

```json
{
      "type": "upload",
      "source": {
        "idOrName": "my-store",
        "files": [
            {
              "key": "my_spreadsheet",
              "name": "My spreadsheet",
              "mimeType": "application/vnd.google-apps.spreadsheet"
            },
            {
              "key": "my_image",
              "name": "My Image"
            }
        ]
      },
      "destination": "My actor files"
    }
```

##### Operation "folders-delete"

Delete a folder. This operation type is useful for deleting folders before uploading files to prevent file duplication.

| Field | Type | Description | Default value | Possible values | Required |
| ----- | ---- | ----------- | ----- | ---- | ----------- |
| folder | string / object | Info of the Google Drive's folder to delete | - | - | true |

**Example:**

```json
{
      "type": "folders-delete",
      "folder": "My Folder"
}
```

#### Is setup mode

Before you start using the actor for running operations, you will need to run it in the setup mode. To achieve that, you need to run it with the bellow input and follow the steps in the run's log ( for more info, check this [article](https://kb.apify.com/integration/google-integration)).

```json
{
  "isSetupMode": true
}
```

**Note**: If the setup mode is activated, operations will not get executed.

# Actor input Schema

## `constants` (type: `array`):

Constants to use in the operations (JSON array)

## `operations` (type: `array`):

The operations to execute

## `fileUploadTimeoutSecs` (type: `integer`):

Required time to upload a single file. Default is 120.

## `fileUploadingMaxConcurrency` (type: `integer`):

Maximum concurrency used for uploading files in parallel.

## `isSetupMode` (type: `boolean`):

Whether yes or no to activate the setup mode.

## `googleOAuthTokensStore` (type: `string`):

Key-value store where your Google OAuth tokens will be stored so you don't have to authorize every time again. By default it is google-oauth-tokens

## `googleOAuthCredentials` (type: `object`):

If you want to use this actor locally or with your own version, you have to provide your own credentials. Check actor readme for more information.

## Actor input object example

```json
{
  "fileUploadTimeoutSecs": 120,
  "isSetupMode": false,
  "googleOAuthTokensStore": "google-oauth-tokens"
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("onidivo/google-drive").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("onidivo/google-drive").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call onidivo/google-drive --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=onidivo/google-drive",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Google Drive",
        "description": "Transfer files between Apify's key-value stores and Google Drive.",
        "version": "0.0",
        "x-build-id": "HzUdiZs955Lov6asp"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/onidivo~google-drive/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-onidivo-google-drive",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/onidivo~google-drive/runs": {
            "post": {
                "operationId": "runs-sync-onidivo-google-drive",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/onidivo~google-drive/run-sync": {
            "post": {
                "operationId": "run-sync-onidivo-google-drive",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "properties": {
                    "constants": {
                        "title": "Constants",
                        "type": "array",
                        "description": "Constants to use in the operations (JSON array)"
                    },
                    "operations": {
                        "title": "Operations",
                        "type": "array",
                        "description": "The operations to execute"
                    },
                    "fileUploadTimeoutSecs": {
                        "title": "File upload timeout seconds",
                        "minimum": 5,
                        "type": "integer",
                        "description": "Required time to upload a single file. Default is 120.",
                        "default": 120
                    },
                    "fileUploadingMaxConcurrency": {
                        "title": "File uploading max concurrency",
                        "type": "integer",
                        "description": "Maximum concurrency used for uploading files in parallel."
                    },
                    "isSetupMode": {
                        "title": "Is setup mode",
                        "type": "boolean",
                        "description": "Whether yes or no to activate the setup mode.",
                        "default": false
                    },
                    "googleOAuthTokensStore": {
                        "title": "Google OAuth tokens store",
                        "type": "string",
                        "description": "Key-value store where your Google OAuth tokens will be stored so you don't have to authorize every time again. By default it is google-oauth-tokens",
                        "default": "google-oauth-tokens"
                    },
                    "googleOAuthCredentials": {
                        "title": "Google OAuth credentials",
                        "type": "object",
                        "description": "If you want to use this actor locally or with your own version, you have to provide your own credentials. Check actor readme for more information."
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
