File size: 957 Bytes
c74033b
 
 
 
 
 
 
 
 
 
 
 
6a0aea0
c74033b
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

import os, pickle
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request

SCOPES = [
    'https://www.googleapis.com/auth/calendar',
    'https://www.googleapis.com/auth/gmail.readonly',
    'https://www.googleapis.com/auth/gmail.send'
]

def authenticate_google_services():
    os.system(f"gdown https://drive.google.com/uc?id=1EVsYlH4LRx4fDcllwfyijJYv6rexUTzR -O client_secret.json")
    creds = None
    if os.path.exists('token.pkl'):
        with open('token.pkl', 'rb') as token:
            creds = pickle.load(token)
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file('client_secret.json', SCOPES)
            creds = flow.run_console()
        with open('token.pkl', 'wb') as token:
            pickle.dump(creds, token)
    return creds