- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试制作一个简单的 python 桌面应用程序来显示我当天的任务。为此,我使用 Google Calendar API 来获取我个人日历的事件。我还应该提到,我是 python 编程的初学者,对 API 本身没有经验,这可能就是我遇到这个问题的原因。
我使用了来自谷歌开发者页面的快速入门代码来获取 API。但由于某种原因,它只返回日历上第一个事件的摘要,当它应该显示前 10 个时。我有一个单独的文件来显示从快速入门返回的数据,但问题不应该在于打印快速入门中的语句也只打印一个事件。
这是我从 Google 的 quickstart.py 中稍微修改的代码:
from __future__ import print_function
import datetime
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
SCOPES = ['https://www.googleapis.com/auth/calendar.readonly']
def main():
"""Shows basic usage of the Google Calendar API.
Prints the start and name of the next 10 events on the user's calendar.
"""
creds = None
# The file token.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists('token.json'):
creds = Credentials.from_authorized_user_file('token.json', SCOPES)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open('token.json', 'w') as token:
token.write(creds.to_json())
service = build('calendar', 'v3', credentials=creds)
# Call the Calendar API
now = datetime.datetime.utcnow().isoformat() + 'Z' # 'Z' indicates UTC time
events_result = service.events().list(calendarId='primary', timeMin=now,
maxResults=10, singleEvents=True,
orderBy='startTime').execute()
events = events_result.get('items', [])
if not events:
print('No upcoming events found.')
for event in events:
time = event['start'].get('dateTime', event['start'].get('date'))
title = event['summary']
# print(event['summary'], time)
return title, time
if __name__ == '__main__':
main()
谷歌开发者 API 引用对我也没有太大帮助,那么有谁知道是什么导致了这个问题?
最佳答案
Execute 按页面返回结果(大小受 maxResults
限制) - 您只看到第一个事件的原因可能是由于 2 个问题:
singleEvents=True
仅返回重复事件的第一个实例。这意味着,如果您的日历有任何重复事件(每天/每周等),您只会在结果中获得该事件的第一次出现。如果您想获取所有事件(据我所知,这就是您想要的)-您需要删除此参数。 result = []
page_token = None
while True:
page = service.events().list(calendarId='primary',
timeMin=now,
maxResults=10,
orderBy='startTime',
pageToken=page_token).execute()
result.extend(page["item"])
page_token = page.get('nextPageToken')
if not page_token:
break
return result
关于python - Google Calendar API 仅获取日历的第一个事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66943079/
也许是一个愚蠢的问题,但我有一个在 Java 文档中没有找到的问题。 Calendar.get(Calendar.DAY_OF_WEEK) 的值是否会根据 Calendar.getFirstDayOf
假设以下代码在 2009 年 8 月 22 日(星期六)执行 Calendar c = Calendar.getInstance(); c.set(Calendar.DAY_OF_WEEK
我正在使用以下代码检查所选月份是否为一月: if (calendar.get(Calendar.MONTH) == Calendar.JANUARY) { ... } 这给了我一个 lint
我有两个 Calendar 变量,分别命名为 calendar1 和 calendar2 其中存储了一些日历值。 我想比较这些变量的 MINUTE 值。 我找到了两种方法,但我想知道有什么区别以及哪一
根据文档 ( here ),Google 提供了一些相同的范围: https://www.googleapis.com/auth/calendar读/写访问到日历 https://www.google
我想问一下,是否可以在不调用 Google 日历 API(需要互联网连接)或启动 native 日历 Activity (不需要)的情况下添加日历事件?只需将日历事件添加到设备 native 日历中(
我们可以从谷歌日历设置中获取工作时间数据吗?我已经了解了日历的 API : https://developers.google.com/calendar/v3/reference/settings/g
我正在尝试使用 Exchange Web 服务访问日历数据,但我似乎无法弄清楚如何访问其他用户共享的日历(当它不是他们的默认日历时)。假设我公司的另一个用户创建了一个共享日历并与我共享,我什至找不到日
我对 Java/Android 中的日期比较有点困惑 DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm");
我正在使用Google的Calendar API,但遇到了一个问题。当我设置要插入的事件的dateTime时,需要设置小时偏移量,但是由于o DST的原因,它需要一个小时。我可以为日历设置一个属性,以
在Google日历的常规网络用户界面中,当我添加事件时,可以选择将其设置为“提醒”,而不是“事件”。 我正在尝试使用Python API进行复制,但是似乎找不到有关如何执行该操作的信息。我找到的所有文
我们可以使用这个link通过参数向Google日历添加新事件 https://www.google.com/calendar/render? action=TEMPLATE& text=EventNa
除了在纪元显式设置它们之外,是否有任何现有方法可以使用日历 API 来获取填充纪元时间的日历?我所能做的就是获取当前时间。 最佳答案 没有预定义的构造函数或工厂方法来执行此操作,但它相当简单: Cal
我试图在我的应用程序上次更新时显示在 TextView 中(例如,“上次更新时间为 12:13”)。我正在尝试使用 Calendar 实例,我认为我理解正确,但我似乎遇到了麻烦. 我知道要获取一个实例
这个问题在这里已经有了答案: Calendar.before(Object when), why Object? (3 个答案) 关闭 8 年前。 我遇到了问题,因为我试图将日期传递给 Calend
在IOS5上使用获取所有日历时 EKEventStore *eventStore = [[EKEventStore alloc] init]; NSArray * calendars = [event
当我运行以下代码时: int year = 2017; int month = 7; int dayOfMonth = 10; Calendar dateOfBirth = new Gregorian
要么我不理解方法 getActualMaximum(int) 或字段 WEEK_OF_YEAR,要么涉及 Sun 错误(或所有三个)...有人可以向我解释为什么(至少在德语语言环境中...) 以下代码
我正在检查我几年前写的代码。然后我意识到 Android Studio 在 Calendar.AM 处给出了注释,它说它必须是 Calendar.SUNDAY、Calendar.MONDAY 之一等等
我需要将给定日期复制 100 次(我无法通过引用传递)。我想知道以下两个中哪个是更好的选择 newTime=Calendar.getInstance().setTime(originalDate);
我是一名优秀的程序员,十分优秀!