I'm using the following script in order to get all today's events from a specific google calendar. the code works for me. The only thing is that the token expires after ~60 min.
How can I make the token refresh automatically?
import requests
import json
import datetime
API_KEY = "******************"
today = datetime.datetime.now().isoformat()
today_date = str(today[:10])
url = f'https://www.googleapis.com/calendar/v3/calendars/****Calendar_ID****/events?maxResults=99999&access_type=offline&approval_prompt=force&key={API_KEY}'
headers = {
'Authorization': 'Bearer *********************************************************'
}
params= {
"timeMin":f"{today_date}T00:00:00-06:00",
"timeMax":f"{today_date}T23:59:59-06:00",
"access_type" : "offline",
"approval_prompt" : "force"
}
response = requests.request("GET", url, headers=headers, params=params)
print(response.text)