i am trying to read my Google Calender events from a specific Calendar without a reauthentication after X hours/days for a dashboards. Is that possible?
I added the "Google Calendar API" to my Google Cloud Platform-project, created a "Desktop client" (with client and secret) and can access my dates via the python api:
SCOPES = [
'https://www.googleapis.com/auth/calendar.readonly', "openid",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/userinfo.profile"
]
client_config = {
'installed': {
'client_id': '123456.apps.googleusercontent.com',
'project_id': 'test-dashboard',
'auth_uri': 'https://accounts.google.com/o/oauth2/auth',
'token_uri': 'https://oauth2.googleapis.com/token',
'auth_provider_x509_cert_url': 'https://www.googleapis.com/oauth2/v1/certs',
'client_secret': 'secret',
'redirect_uris': ['urn:ietf:wg:oauth:2.0:oob', 'http://localhost']
}
}
flow = InstalledAppFlow.from_client_config(client_config, SCOPES)
credentials = flow.run_local_server()
service = build('calendar', 'v3', credentials = credentials)
page_token = None
cal = {}
while True:
calendar_list = service.calendarList().list(pageToken=page_token).execute()
for calendar_list_entry in calendar_list['items']:
cal[calendar_list_entry['summary']] = calendar_list_entry
page_token = calendar_list.get('nextPageToken')
if not page_token:
break
But the problem is, that flow.run_local_server()
ask everytime for my Google Account, which is not possible for a 24/7 running dashboard.
Kind regards
Edit: I am using a standard gmail-account within gcp. I tried it with a service account, but the result, if i use this method, is empty and not the events from my gmail account. Is it possible to get the calenders events from my personal account via the service account?
If i am using domain-wide delegation, i could request the calendar events from the domain, but that would not help me to receive the events from the personal account, does it?