Guest User

Untitled

a guest
Dec 18th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. SCOPES = 'https://www.googleapis.com/auth/calendar'
  2. CLIENT_SECRET_FILE = 'client_id.json'
  3. APPLICATION_NAME = 'Google Calendar API Python Quickstart'
  4.  
  5.  
  6. def get_credentials():
  7.  
  8. home_dir = os.path.expanduser('~')
  9. credential_dir = os.path.join(home_dir, '.credentials')
  10. if not os.path.exists(credential_dir):
  11. os.makedirs(credential_dir)
  12. credential_path = os.path.join(credential_dir,
  13. 'calendar-python-quickstart.json')
  14.  
  15. store = Storage(credential_path)
  16. credentials = store.get()
  17. if not credentials or credentials.invalid:
  18. flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
  19. flow.user_agent = APPLICATION_NAME
  20. if flags:
  21. credentials = tools.run_flow(flow, store, flags)
  22. else: # Needed only for compatibility with Python 2.6
  23. credentials = tools.run(flow, store)
  24. print('Storing credentials to ' + credential_path)
  25. return credentials
  26.  
  27.  
  28. credentials = get_credentials()
  29. http = credentials.authorize(httplib2.Http())
  30. service = discovery.build('calendar', 'v3', http=http)
Add Comment
Please, Sign In to add comment