FakeNews_Detector / fix_verification_issue.py
NLong's picture
Upload 12 files
b5fb8d2 verified
#!/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: [email protected]")
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()