Google 日历查询最多返回 25 个条目
我正在尝试删除从今天开始的所有日历条目。我运行一个查询,然后对查询结果调用 getEntries() 。 getEntries() 始终返回 25 个条目(如果日历上的条目少于 25 个,则返回更少)。为什么没有返回所有条目?我预计大约有 80 个条目。
作为测试,我尝试运行查询,删除返回的 25 个条目,再次运行查询,再次删除等等。这可行,但必须有更好的方法。
下面是只运行一次查询的 Java 代码。
CalendarQuery myQuery = new CalendarQuery(feedUrl);
DateFormat dfGoogle = new SimpleDateFormat("yyyy-MM-dd'T00:00:00'");
Date dt = Calendar.getInstance().getTime();
myQuery.setMinimumStartTime(DateTime.parseDateTime(dfGoogle.format(dt)));
// Make the end time far into the future so we delete everything
myQuery.setMaximumStartTime(DateTime.parseDateTime("2099-12-31T23:59:59"));
// Execute the query and get the response
CalendarEventFeed resultFeed = service.query(myQuery, CalendarEventFeed.class);
// !!! This returns 25 (or less if there are fewer than 25 entries on the calendar) !!!
int test = resultFeed.getEntries().size();
// Delete all the entries returned by the query
for (int j = 0; j < resultFeed.getEntries().size(); j++) {
CalendarEventEntry entry = resultFeed.getEntries().get(j);
entry.delete();
}
PS:我查看了数据 API 开发人员指南以及 Google Data API Javadoc。这些网站还可以,但不是很好。有谁知道额外的 Google API 文档吗?
I'm trying to delete all calendar entries from today forward. I run a query then call getEntries() on the query result. getEntries() always returns 25 entries (or less if there are fewer than 25 entries on the calendar). Why aren't all the entries returned? I'm expecting about 80 entries.
As a test, I tried running the query, deleting the 25 entries returned, running the query again, deleting again, etc. This works, but there must be a better way.
Below is the Java code that only runs the query once.
CalendarQuery myQuery = new CalendarQuery(feedUrl);
DateFormat dfGoogle = new SimpleDateFormat("yyyy-MM-dd'T00:00:00'");
Date dt = Calendar.getInstance().getTime();
myQuery.setMinimumStartTime(DateTime.parseDateTime(dfGoogle.format(dt)));
// Make the end time far into the future so we delete everything
myQuery.setMaximumStartTime(DateTime.parseDateTime("2099-12-31T23:59:59"));
// Execute the query and get the response
CalendarEventFeed resultFeed = service.query(myQuery, CalendarEventFeed.class);
// !!! This returns 25 (or less if there are fewer than 25 entries on the calendar) !!!
int test = resultFeed.getEntries().size();
// Delete all the entries returned by the query
for (int j = 0; j < resultFeed.getEntries().size(); j++) {
CalendarEventEntry entry = resultFeed.getEntries().get(j);
entry.delete();
}
PS: I've looked at the Data API Developer's Guide and the Google Data API Javadoc. These sites are okay, but not great. Does anyone know of additional Google API documentation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用
myQuery.setMaxResults()
增加结果数量。不过,会有一个最大的最大值,因此您可以通过改变myQuery.setStartIndex()
来进行多个查询(“分页”结果)。http://code. google.com/apis/gdata/javadoc/com/google/gdata/client/Query.html#setMaxResults(int)
http://code. google.com/apis/gdata/javadoc/com/google/gdata/client/Query.html#setStartIndex(int)
You can increase the number of results with
myQuery.setMaxResults()
. There will be a maximum maximum though, so you can make multiple queries ('paged' results) by varyingmyQuery.setStartIndex()
.http://code.google.com/apis/gdata/javadoc/com/google/gdata/client/Query.html#setMaxResults(int)
http://code.google.com/apis/gdata/javadoc/com/google/gdata/client/Query.html#setStartIndex(int)
根据 Jim Blackler 和 Chris Kaminski 的回答,我增强了代码以读取页面中的查询结果。我还进行批量删除,这应该比单独删除要快。
我在这里提供 Java 代码,以防它对任何人有用。
Based on the answers from Jim Blackler and Chris Kaminski, I enhanced my code to read the query results in pages. I also do the delete as a batch, which should be faster than doing individual deletions.
I'm providing the Java code here in case it is useful to anyone.
API页面上有一个小引用
http://code.google.com/apis/calendar/ data/1.0/reference.html#参数
因此,要从 Google 日历 Feed 获取所有事件,我们执行以下操作:
google.calendarurl.com/.../basic?max-results=999999
您也可以使用 setMaxResults=999999 进行查询API 中的
There is a small quote on the API page
http://code.google.com/apis/calendar/data/1.0/reference.html#Parameters
So to get all events from a google calendar feed, we do this:
google.calendarurl.com/.../basic?max-results=999999
in the API you can also query with setMaxResults=999999
我是在寻找 Python 解决方案时来到这里的;
如果有人遇到同样的问题,重要的是第四行:
I got here while searching for a Python solution;
Should anyone be stuck in the same way, the important line is the fourth:
不幸的是,谷歌将限制您可以检索的最大查询数量。这是为了让查询调控器遵守其指导原则(例如,HTTP 请求的时间不允许超过 30 秒)。他们已经围绕此构建了整个架构,因此您不妨构建现有的逻辑。
Unfortunately, Google is going to limit the maximum number of queries you can retrieve. This is so as to keep the query governor in their guidelines (HTTP requests not allowed to take more than 30 seconds, for example). They've built their whole architecture around this, so you might as well build the logic as you have.