Skip to content

Google - DriveÂķ

Interact and perform various operations through a Google account. Download, upload and manage files easily via the BotCity plugin for Google Drive.

InstallationÂķ

pip install botcity-googledrive-plugin

Importing the PluginÂķ

After you installed this package and get the Google credentials file, the next step is to import the package into your code and start using the functions.

from botcity.plugins.googledrive import BotGoogleDrivePlugin

Searching for a fileÂķ

To make the example we will instantiate the plugin and search for a file by name.

# Set the path of the credentials json file
credentials = './resources/credentials.json'

# Instantiate the plugin
googledrive = BotGoogleDrivePlugin(credentials)

# Get the id of the file named "my_image.png" stored on the drive
file_id = googledrive.search_file_by_name("my_image.png")

Downloading a fileÂķ

Now let's download the file we searched for in the step above.

# With the obtained id, download the file
googledrive.download_file(file_id, './images/my_image_from_drive.png')

Complete codeÂķ

Let's take a look into the complete code:

# Import the plugin
from botcity.plugins.googledrive import BotGoogleDrivePlugin

# Set the path of the credentials json file
credentials = './resources/credentials.json'

# Instantiate the plugin
googledrive = BotGoogleDrivePlugin(credentials)

# Get the id of the file named "my_image.png" stored on the drive
file_id = googledrive.search_file_by_name("my_image.png")

# With the obtained id, download the file
googledrive.download_file(file_id, './images/my_image_from_drive.png')