Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何在太平洋时区使用谷歌日历API获取我今天的所有活动_Python 3.x_Google Calendar Api - Fatal编程技术网

Python 3.x 如何在太平洋时区使用谷歌日历API获取我今天的所有活动

Python 3.x 如何在太平洋时区使用谷歌日历API获取我今天的所有活动,python-3.x,google-calendar-api,Python 3.x,Google Calendar Api,我正在尝试使用谷歌日历API从一天的开始到一天的结束提取所有每日事件。我使用API遵循google的quickstart程序,但它给了我接下来的10个事件以及UTC时区的0偏移量。我只想抓拍当天和“美国/洛杉矶”时区的活动 now = datetime.datetime.utcnow().isoformat() + 'Z' print('Getting todays events') events_results = service.events().list(calen

我正在尝试使用谷歌日历API从一天的开始到一天的结束提取所有每日事件。我使用API遵循google的quickstart程序,但它给了我接下来的10个事件以及UTC时区的0偏移量。我只想抓拍当天和“美国/洛杉矶”时区的活动

    now = datetime.datetime.utcnow().isoformat() + 'Z'
    print('Getting todays events')
    events_results = service.events().list(calendarId='primary', timeMin=now,
                                        maxResults=10, singleEvents=True,
                                        orderBy='startTime').execute()

您可以对脚本进行以下更改:

today = datetime.datetime.today();
start = (datetime.datetime(today.year, today.month, today.day, 00, 00)).isoformat() + 'Z'
tomorrow = today + datetime.timedelta(days=1)
end =  (datetime.datetime(tomorrow.year, tomorrow.month, tomorrow.day, 00, 00)).isoformat() + 'Z'
print('Getting todays events')
events_results = service.events().list(calendarId='primary', timeMin=start, timeMax=end, singleEvents=True, orderBy='startTime').execute()
如果要从今天检索所有事件,必须使用
timeMin
timeMax
参数。
timeMin
将设置为今天的日期小时
00:00
,而
timeMax
则表示这一天的结束-因此选择了使用
00:00
设置的明天日期

此外,此处不需要
maxResults
参数,因为您希望检索所有事件,而不是有限的数量

请记住,为
时间最小值
时间最大值
提供的日期都是独占边界,它们必须是带有强制时区偏移的RFC3339时间戳

对于将来的请求,您还可以使用来模拟它们并测试所需的参数

参考文献
  • )


您好,感谢您的帮助和宝贵时间。但是,我尝试了您的解决方案,但当我尝试编译它时,它不起作用。错误代码:googleapiclient.errors.HttpError:@Matt,我已经更新了我的答案。此外,请记住,如果您想查看结果,可能需要打印结果。干杯