This Python program is used to interact with Google Drive using the Google Drive API. It allows you to initialize a service, get a folder ID by its name, and list all files in a specific folder.
- Pre-requisites
- Import the necessary classes from the
drive_api
module:
from drive_api import ServiceAccountDrive
ServiceAccountDriveInstance = ServiceAccountDrive()
- Initialize the Google Drive service:
cred = "path_to_your_credentials_file.json"
service, credentials = ServiceAccountDriveInstance.initialize_drive_service(creds=cred)
In this step, replace "path_to_your_credentials_file.json"
with the path to your Google Drive API credentials file.
- Get the folder ID by its name:
folder_id = ServiceAccountDrive.get_folder_id_by_name("Folder Name")
Replace "Folder Name"
with the name of the folder you're interested in.
- List all files in a specific folder:
files = ServiceAccountDrive.list_files_in_folder(folder_id)
Replace folder_id
with the folder ID you got in the previous step.
- Download file from drive
ServiceAccountDrive.download_file_from_drive("file_id", "path/to/save")
Replace file_id
with the file ID and replace path/to/save
with saved path