You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from google.oauth2.credentials import Credentials
from google.oauth2 import id_token
from google.auth.transport import requests
from googleapiclient.discovery import build
# Obtain the ID token from the client-side authentication flow
id_token = 'your_id_token_here'
# Verify the ID token
client_id = 'your_client_id_here'
try:
idinfo = id_token.verify_oauth2_token(id_token, requests.Request(), client_id)
if idinfo['iss'] not in ['accounts.google.com', 'https://accounts.google.com']:
raise ValueError('Invalid issuer.')
# Get the user's email address and user ID
email = idinfo['email']
user_id = idinfo['sub']
except ValueError:
# Invalid token
pass
# Build the credentials object using the access token
creds = Credentials.from_authorized_user_info(info=idinfo)
# Build the Calendar API client
service = build('calendar', 'v3', credentials=creds)
# Ask the user to select a calendar to access
calendar_list = service.calendarList().list().execute()
for i, calendar in enumerate(calendar_list['items']):
print(f"{i + 1}. {calendar['summary']}")
calendar_index = int(input("Select a calendar to access: ")) - 1
calendar_id = calendar_list['items'][calendar_index]['id']
# Set the date range for the events you want to retrieve
start_date = datetime.datetime.utcnow().isoformat() + 'Z'
end_date = (datetime.datetime.utcnow() + datetime.timedelta(days=7)).isoformat() + 'Z'
# Retrieve events from the calendar
events_result = service.events().list(calendarId=calendar_id, timeMin=start_date, timeMax=end_date, singleEvents=True, orderBy='startTime').execute()
events = events_result.get('items', [])
# Print out the events
if not events:
print('No events found for the specified date range.')
else:
print('Upcoming events:')
for event in events:
start = event['start'].get('dateTime', event['start'].get('date'))
print(f'{start} - {event["summary"]}')
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: