Spaces:
Sleeping
Sleeping
A newer version of the Gradio SDK is available: 6.11.0
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
- In a Python shell run:
from google_drive_sync import get_refresh_token
refresh_token = get_refresh_token()
- A browser window opens for Google sign-in
- 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
- Visit Google Cloud Console
- Select or create a project
- Enable the Google Drive API
- Go to “IAM & Admin” → “Service Accounts”
- Click “Create Service Account”
- Provide a name/description, click “Create and Continue”
- Grant the “Editor” role, then “Continue” → “Done”
Step 2: Create and download the key
- Open the Service Account
- Go to the “Keys” tab
- Click “Add Key” → “Create new key”
- Choose JSON → “Create”
- Save the JSON into your project directory (e.g.,
service-account-key.json)
Step 3: Share the Drive folder with the Service Account
- Create a folder in Drive (e.g., “Chatbot_Data”)
- Right-click → “Share”
- In the JSON file find
client_email(looks likexxx@xxx.iam.gserviceaccount.com) - 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:
- Refresh token or Service Account path is correct
- Network connectivity
- Google Drive API is enabled
- Service Account has access to the folder
Notes
⚠️ Security reminders
- Never commit credentials to public repos
- Add
google_drive_sync.pyor secrets to.gitignoreif 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
- Double-check
CLIENT_ID/CLIENT_SECRET - Confirm the Drive API is enabled
- Verify your network connection