Advertisement
gandalfbialy

Untitled

May 31st, 2025
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. #kod do uruchomienia lokalnie na komputerze
  2. import os
  3. import pickle
  4. from google_auth_oauthlib.flow import InstalledAppFlow
  5. from googleapiclient.discovery import build
  6.  
  7. SCOPES = ['https://www.googleapis.com/auth/gmail.modify']
  8.  
  9. def authorize_and_save_token():
  10.     if os.path.exists('token.pkl'):
  11.         print("Plik token.pkl już istnieje.")
  12.         return
  13.  
  14.     flow = InstalledAppFlow.from_client_secrets_file('credentials.json', SCOPES)
  15.     creds = flow.run_local_server(port=0)
  16.  
  17.     with open('token.pkl', 'wb') as token_file:
  18.         pickle.dump(creds, token_file)
  19.     print("Autoryzacja zakończona i token zapisany jako token.pkl.")
  20.  
  21.     service = build('gmail', 'v1', credentials=creds)
  22.     results = service.users().labels().list(userId='me').execute()
  23.     print("Twoje etykiety Gmail:")
  24.     for label in results.get('labels', []):
  25.         print("•", label['name'])
  26.  
  27. if __name__ == '__main__':
  28.     authorize_and_save_token()
  29.  
  30.  
  31.  
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement