chatbot-mimic-notes / google_drive_setup_guide.md
Jesse Liu
init hf
6a725a4

A newer version of the Gradio SDK is available: 6.11.0

Upgrade

Google Drive Hard-Coded Auth Guide

Use this guide to enable automatic Drive uploads without running OAuth each time.

Option 1: Refresh Token (recommended, simple)

Step 1: Obtain a refresh token

  1. In a Python shell run:
from google_drive_sync import get_refresh_token
refresh_token = get_refresh_token()
  1. A browser window opens for Google sign-in
  2. The terminal prints your refresh_token, e.g.
    REFRESH_TOKEN = "1//0gxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    

Step 2: Configure the refresh token

Open google_drive_sync.py and set:

REFRESH_TOKEN = None  # place your refresh token here

Replace None with your token:

REFRESH_TOKEN = "1//0gxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"  # your refresh token

Step 3: Done

Save the file; future uploads happen automatically without another login.


Option 2: Service Account (more secure, production-friendly)

Step 1: Create the Service Account

  1. Visit Google Cloud Console
  2. Select or create a project
  3. Enable the Google Drive API
  4. Go to “IAM & Admin” → “Service Accounts”
  5. Click “Create Service Account”
  6. Provide a name/description, click “Create and Continue”
  7. Grant the “Editor” role, then “Continue” → “Done”

Step 2: Create and download the key

  1. Open the Service Account
  2. Go to the “Keys” tab
  3. Click “Add Key” → “Create new key”
  4. Choose JSON → “Create”
  5. Save the JSON into your project directory (e.g., service-account-key.json)

Step 3: Share the Drive folder with the Service Account

  1. Create a folder in Drive (e.g., “Chatbot_Data”)
  2. Right-click → “Share”
  3. In the JSON file find client_email (looks like xxx@xxx.iam.gserviceaccount.com)
  4. Add that email to the folder with “Editor” access

Step 4: Point the code to the Service Account file

Set this in google_drive_sync.py:

SERVICE_ACCOUNT_FILE = None  # e.g. "path/to/service-account-key.json"

Replace None with your JSON path:

SERVICE_ACCOUNT_FILE = "service-account-key.json"  # your Service Account JSON path

Step 5: Done

All data now syncs to the folder you shared with the Service Account!


Verify the setup

Run the app and confirm uploads reach Drive. If not, check:

  1. Refresh token or Service Account path is correct
  2. Network connectivity
  3. Google Drive API is enabled
  4. Service Account has access to the folder

Notes

⚠️ Security reminders

  • Never commit credentials to public repos
  • Add google_drive_sync.py or secrets to .gitignore if needed
  • Protect the Service Account JSON carefully

Troubleshooting

Refresh token expired

Re-run get_refresh_token() to obtain a new one.

Service Account can’t access the folder

Ensure the Service Account email was invited with the proper permission.

Authentication failure

  1. Double-check CLIENT_ID / CLIENT_SECRET
  2. Confirm the Drive API is enabled
  3. Verify your network connection