import json
from google.oauth2 import service_account
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError

SERVICE_ACCOUNT_FILE = '/home/openclaw/.openclaw/workspace/google_service_account.json'
SCOPES = ['https://www.googleapis.com/auth/drive.readonly']

def test_access(file_id):
    try:
        creds = service_account.Credentials.from_service_account_file(
            SERVICE_ACCOUNT_FILE, scopes=SCOPES)
        service = build('drive', 'v3', credentials=creds)
        result = service.files().get(fileId=file_id, fields='id, name, mimeType').execute()
        print("SUCCESS:", json.dumps(result, indent=2))
        return True
    except HttpError as e:
        print(f"HTTP Error {e.resp.status}: {e.reason}")
        print(e.content.decode())
        return False
    except Exception as e:
        print(f"Other error: {e}")
        return False

if __name__ == '__main__':
    # Test with the file ID from check_drive.py
    file_id = "1zsVzSUTicnX4CWjgOp5Bj9cSXo7YuL9w"
    print(f"Testing access to file ID: {file_id}")
    test_access(file_id)