mirror-leech-telegram-bot/generate_drive_token.py
anasty17 3ecb731ad1 Init
Signed-off-by: anasty17 <e.anastayyar@gmail.com>
2021-11-23 04:57:18 +02:00

26 lines
874 B
Python

import pickle
import os
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
credentials = None
__G_DRIVE_TOKEN_FILE = "token.pickle"
__OAUTH_SCOPE = ["https://www.googleapis.com/auth/drive"]
if os.path.exists(__G_DRIVE_TOKEN_FILE):
with open(__G_DRIVE_TOKEN_FILE, 'rb') as f:
credentials = pickle.load(f)
if (
(credentials is None or not credentials.valid)
and credentials
and credentials.expired
and credentials.refresh_token
):
credentials.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', __OAUTH_SCOPE)
credentials = flow.run_console(port=0)
# Save the credentials for the next run
with open(__G_DRIVE_TOKEN_FILE, 'wb') as token:
pickle.dump(credentials, token)