#!/usr/bin/env python3 """ Fix Google verification issue for OAuth """ import os import json from google.oauth2.credentials import Credentials from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request # Configuration SCOPES = ['https://www.googleapis.com/auth/drive.file'] CREDENTIALS_FILE = 'credentials.json' TOKEN_FILE = 'token.json' def fix_verification_issue(): """Fix Google verification issue""" print("๐Ÿ”ง Fixing Google Verification Issue") print("=" * 50) print("๐Ÿ“‹ The issue is that your app needs to be in 'Testing' mode") print(" and you need to be added as a test user.") print() print("๐Ÿ”ง Manual Fix Required:") print("1. Go to: https://console.cloud.google.com/") print("2. APIs & Services โ†’ OAuth consent screen") print("3. Make sure 'Publishing status' is set to 'Testing'") print("4. Scroll down to 'Test users' section") print("5. Click 'Add Users'") print("6. Add your email: kienn232@gmail.com") print("7. Save the changes") print() print("๐Ÿ”„ Alternative: Change User Type to Internal") print(" (If you have a Google Workspace account)") print() # Check if credentials exist if not os.path.exists(CREDENTIALS_FILE): print(f"โŒ {CREDENTIALS_FILE} not found!") return False # Delete old token file if os.path.exists(TOKEN_FILE): print(f"๐Ÿ—‘๏ธ Removing old token file: {TOKEN_FILE}") os.remove(TOKEN_FILE) print("โœ… Ready to test after you add yourself as a test user") print() # Ask user if they've completed the steps response = input("Have you added yourself as a test user? (y/n): ").strip().lower() if response == 'y': print("\n๐Ÿงช Testing authentication...") try: # Try authentication flow = InstalledAppFlow.from_client_secrets_file(CREDENTIALS_FILE, SCOPES) creds = flow.run_local_server(port=0) print("โœ… Authentication successful!") # Save credentials with open(TOKEN_FILE, 'w') as token: token.write(creds.to_json()) print(f"โœ… Credentials saved to {TOKEN_FILE}") # Test Google Drive access print("\n๐Ÿงช Testing Google Drive access...") from googleapiclient.discovery import build service = build('drive', 'v3', credentials=creds) results = service.files().list(pageSize=1, fields="files(id, name)").execute() files = results.get('files', []) print("โœ… Google Drive access successful!") print(f" Found {len(files)} file(s) in your Drive") return True except Exception as e: error_msg = str(e).lower() if "access_denied" in error_msg or "verification" in error_msg: print("โŒ Still getting verification error") print("๐Ÿ’ก Make sure you:") print(" 1. Added yourself as a test user") print(" 2. Set publishing status to 'Testing'") print(" 3. Saved all changes") return False else: print(f"โŒ Authentication failed: {e}") return False else: print("๐Ÿ’ก Please complete the steps above and run this script again") return False def main(): """Main function""" print("๐Ÿš€ Google Verification Fix for RAG System") print("=" * 50) if fix_verification_issue(): print("\n๐ŸŽ‰ Verification issue fixed!") print("โœ… You can now run: python setup_google_drive_rag.py") else: print("\nโŒ Please complete the manual steps above") if __name__ == "__main__": main()