Skip to content

Google Drive Integration

Setup

  1. Enable Google Drive API
  2. Go to Google Cloud Console
  3. Navigate to APIs & Services > Library
  4. Search for and enable "Google Drive API"

  5. Generate Credentials

  6. Go to APIs & Services > Credentials
  7. Click "Create Credentials" > "OAuth 2.0 Client ID"
  8. Select "Desktop Application"
  9. Download the credentials file as credentials.json
  10. Place it in your project root directory

  11. Configure Environment Variables No environment variables needed, but ensure credentials.json is in your project root.

Basic Setup

from src.tools.google_drive import authenticate_google_drive, search_files, upload_file, download_file

# Initialize Google Drive service
service = authenticate_google_drive()

# Search for files
results = search_files(service, "name contains 'report'")

# Upload a file
file_id = upload_file(service, 
    file_path="path/to/file.pdf",
    mime_type="application/pdf"
)

# Download a file
download_file(service,
    file_id="your_file_id",
    destination="path/to/save/file.pdf"
)

Features

  • OAuth2 authentication flow
  • File search with custom queries
  • File upload with MIME type support
  • File download with progress tracking
  • Token persistence for future sessions
  • Automatic token refresh
  • Error handling and logging

TODOs for Future Enhancements:

  • Add support for folder operations
  • Implement file sharing functionality
  • Add batch upload/download support
  • Add support for editing Google Sheets and Docs.
  • Implement real-time notifications for file updates using Google Drive API webhooks.
  • Add support for Google Sheets/Docs creation
  • Add support for Team Drives
  • Implement file change tracking
  • Handle advanced file sharing and permission settings.

Reference

For implementation details, see: src/tools/google_drive.py

The implementation uses the official Google Drive API v3. For more information, refer to: - Google Drive API Documentation - Google Auth Library for Python