从日历api python获取当前日期

从日历api python获取当前日期,python,datetime,google-calendar-api,Python,Datetime,Google Calendar Api,我正在尝试制作一个python程序,在这个程序中,我可以在指定的时间段内获取google提醒,比如从(当前日期前2天)到(当前日期后2天)。但是我不能从google calendars API获取当前日期。它给了我一个“糟糕的要求”。我甚至尝试过将当前日期保存在一个变量中,然后在timeMin和timeMax命令中调用它,但没有成功。获取当前日期的最佳方法是什么?任何帮助都将不胜感激。以下是我的代码:- from apiclient.discovery import build from goo

我正在尝试制作一个python程序,在这个程序中,我可以在指定的时间段内获取google提醒,比如从(当前日期前2天)到(当前日期后2天)。但是我不能从google calendars API获取当前日期。它给了我一个“糟糕的要求”。我甚至尝试过将当前日期保存在一个变量中,然后在timeMin和timeMax命令中调用它,但没有成功。获取当前日期的最佳方法是什么?任何帮助都将不胜感激。以下是我的代码:-

from apiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
import pickle
import time

scopes = ['https://www.googleapis.com/auth/calendar']

#flow = InstalledAppFlow.from_client_secrets_file("client_secret.json", scopes=scopes)
#credentials = flow.run_console()

#pickle.dump(credentials, open("token.pkl", "wb"))
credentials = pickle.load(open("token.pkl", "rb"))
service = build("calendar", "v3" , credentials=credentials)
now = datetime.time.today()
diff = datetime.timedelta(2)

Mintime = now - diff
Maxtime = now + diff
result = service.calendarList().list().execute()
#first = result['items'][0]
second = result['items'][1]
#third = result['items'][2]
#fourth = result['items'][3]
calendar_id = result['items'][1]['id']

result_new = service.events().list(calendarId=calendar_id).execute()
result_newer = result_new['items'][0]['summary']
print(result_newer)

请您提供错误消息好吗?这是确切的错误:-raise HttpError(resp,content,uri=self.uri)GoogleAppClient.errors.HttpError:@HuwThomas我自己解决了错误。我只是将日期保存在名为Mintime的变量中,但是我还必须传入时间,因此我手动将时间字符串与之关联,现在它返回正确的项目。