Download src/generate_token.py from ayush77uh/live: direct link, hf CLI and curl.
- Browser
- Download file 2.66 kB
-
https://huggingface.co/spaces/ayush77uh/live/resolve/main/src/generate_token.py
- Command line
-
hf download hf://spaces/ayush77uh/live/src/generate_token.py
-
curl -L -o generate_token.py https://huggingface.co/spaces/ayush77uh/live/resolve/main/src/generate_token.py
2.66 kB
| """ | |
| Generate Google OAuth Refresh Token for Drive API | |
| Run this locally to get a new refresh token, then add it to HF Space secrets | |
| """ | |
| import os | |
| import json | |
| from google_auth_oauthlib.flow import InstalledAppFlow | |
| from google.auth.transport.requests import Request | |
| # OAuth scopes needed | |
| SCOPES = ['https://www.googleapis.com/auth/drive'] | |
| def main(): | |
| print("=" * 60) | |
| print("Google Drive OAuth Token Generator") | |
| print("=" * 60) | |
| print() | |
| # Check for client credentials | |
| client_id = input("Enter GOOGLE_OAUTH_CLIENT_ID: ").strip() | |
| client_secret = input("Enter GOOGLE_OAUTH_CLIENT_SECRET: ").strip() | |
| if not client_id or not client_secret: | |
| print("❌ Client ID and Secret are required!") | |
| return | |
| # Create client secrets dict | |
| client_config = { | |
| "installed": { | |
| "client_id": client_id, | |
| "client_secret": client_secret, | |
| "auth_uri": "https://accounts.google.com/o/oauth2/auth", | |
| "token_uri": "https://oauth2.googleapis.com/token", | |
| "redirect_uris": ["urn:ietf:wg:oauth:2.0:oob", "http://localhost"] | |
| } | |
| } | |
| print() | |
| print("Starting OAuth flow...") | |
| print("A browser window will open. Please authorize the application.") | |
| print() | |
| try: | |
| # Run OAuth flow | |
| flow = InstalledAppFlow.from_client_config( | |
| client_config, | |
| SCOPES, | |
| redirect_uri='http://localhost:8080' | |
| ) | |
| credentials = flow.run_local_server(port=8080) | |
| print() | |
| print("=" * 60) | |
| print("✅ SUCCESS! Copy these values to HF Space secrets:") | |
| print("=" * 60) | |
| print() | |
| print(f"GOOGLE_OAUTH_CLIENT_ID={client_id}") | |
| print(f"GOOGLE_OAUTH_CLIENT_SECRET={client_secret}") | |
| print(f"GOOGLE_DRIVE_REFRESH_TOKEN={credentials.refresh_token}") | |
| print() | |
| print("⚠️ IMPORTANT: Keep the REFRESH_TOKEN secret!") | |
| print(" Add it to: HF Space → Settings → Repository secrets") | |
| print() | |
| # Save to file for convenience | |
| with open('.env.local', 'w') as f: | |
| f.write(f"GOOGLE_OAUTH_CLIENT_ID={client_id}\n") | |
| f.write(f"GOOGLE_OAUTH_CLIENT_SECRET={client_secret}\n") | |
| f.write(f"GOOGLE_DRIVE_REFRESH_TOKEN={credentials.refresh_token}\n") | |
| print("📁 Also saved to .env.local file") | |
| except Exception as e: | |
| print(f"\n❌ Error: {e}") | |
| print("\nMake sure you have the google-auth-oauthlib package installed:") | |
| print(" pip install google-auth-oauthlib") | |
| if __name__ == "__main__": | |
| main() | |