Google日历v3 API [Events:list]请求返回空列表 [英] Google Calendar v3 API [Events: list] request return Empty List

查看:130
本文介绍了Google日历v3 API [Events:list]请求返回空列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



现在,问题是当我提出' Events:list ',然后我得到零个项目,尽管有
$ b

示例

  {kind:calendar#events,
nextPageToken:CigKGm83a292ZzZ2YXBsNXRsMHJhZnV2cGprdHVvGAEggIDA97TfuYYUGg0IABIAGOjEqd_6q7kC,
items:[]
}

如果我在下一个请求中使用了 nextPageToken ,那么正常工作。不想提出任何额外请求。)



每次都不会发生此问题。如果我创建新的email_id,这工作正常。但在一两个月后,这个问题再次出现。


这是Google Calendar API中的错误吗?





有没有解决方法可以在一个请求中获取任何日历的事件列表?


预先致谢。

解决方案

我一直试图找出相同的问题,我相信我有答案。



这里的问题是,当Google计算要返回的事件的页面时,在计算中包含已删除的事件,并且您的第一页充满了您没有看到的已删除事件,除非您的请求具有showDeleted = True。

我提供一种让用户清除他们的日历并重新填充并且遇到这个问题的方法。考虑这种情况:


  • 用户在其日历中有250个事件并且出于参数目的,可以说Google的页面大小为当用户运行该流程重新填充时,这250个事件将被删除,并创建250个'新'事件。

  • li>
  • 当我们接下来在重新填充过程之前删除事件时,第一页返回时没有事件 - 这是因为列表中的前250个是原来被删除的。 (我已使用 API资源管理器验证了这一点) p>


  • 使用nextPageToken获取结果的下一页 - 正如您已经注意到的那样。 >这就是为什么创建一个新的日历能够在一段时间内运行 - 也就是说,直到你克服了页面限制并开始返回0个事件,这就是我们遇到问题的地方。$ b $随着时间的推移,如果用户使用这种重新填充功能很多,他们的
    列表删除事件可能会变得很大,并且需要许多
    请求才能返回所有事件。 (我知道没有办法从Google Cal中完全清除所有已删除的
    事件 - 它们似乎永远保留下来)


  • 没有办法知道在一次通话中返回所有事件。您需要一次循环获取页面的过程,直到NextPageToken不再返回。这是有道理的,因为对于拥有1000个约会的巨大日历的用户来说,在一个请求中返回所有内容是低效的。




<这里使用Google Calendar API V3是我在VB.Net中使用的一个示例,用于删除所有事件。 (Service是一个Google.Apis.Calendar.v3.CalendarService)

  Private Sub ClearAllEvents()

Dim pageToken As String = Nothing
Dim events As Events
Dim qry As New ListRequest(Service,GCalId)


qry.PageToken = pageToken
事件= qry.Execute()
For Each ev As [Event] In events.Items
Dim dr As New DeleteRequest(Service,GCalId,ev.Id)
dr.Execute()
Next
pageToken = events.NextPageToken
Loop While Not IsNothing(pageToken)
End Sub


i'm using python urllib for making request on Google calendar(API V3).

Now,Problem is that when i make request for 'Events: list',then i got zero items in response although there are events in that calendar.

Example

   {  "kind": "calendar#events",
   "nextPageToken": "CigKGm83a292ZzZ2YXBsNXRsMHJhZnV2cGprdHVvGAEggIDA97TfuYYUGg0IABIAGOjEqd_6q7kC",
   "items": [  ] 
   }

If i use 'nextPageToken' in next request it works fine.(But i don't want make any Extra request.)

This problem not occur every time. If i create new email_id this works fine. but after one or two month this problem start again.

Is this a bug in Google Calendar API ?

or

Is there any solution to get event list of any calendar in just One Request ?

Thanks in advance.

解决方案

I've been trying to figure out the same issue and I believe I have the answer.

The issue here is that when Google calculates a 'page' of events to return, it includes the deleted events in that calculation, and your first page is full of deleted events that you don't see unless your request has "showDeleted = True".

I provide a way for the user to 'clear' their calendar and repopulate it and have run into this issue. Consider this scenario:

  • The user has 250 events in their calendar and for arguments sake, lets say Googles 'page' size the same size.

  • When the user runs the process to repopulate, these 250 events are removed and 250 'new' events are created.

  • When we next go to remove the events prior to a repopulate process, the first page returns with no events - this is because the first 250 in the list are those that were deleted originally. (I have verified this by using the API Explorer )

  • Using the nextPageToken to get the next page of results works - as you have noted.

  • This is why creating a new calendar works for a period of time - ie until you get over that 'page' limit and start returning 0 events, which is where we run into issues.

  • Over time and if the user uses this repopulate function a lot, their list of deleted events can become huge and it will require many requests to return all Events. (I know of no way to purge all the deleted events completely from Google Cal - they seem to remain forever)

  • There is no way I know of to return all events in one call. You need to loop through the process getting a page at a time until the "NextPageToken" is no longer returned. This makes sense, because for users that have huge calendars with 1000's of appointments, it's inefficient to return everything in one request.

Using the Google Calendar API V3 here is a sample of what I'm using in VB.Net to remove all Events. (Service is a Google.Apis.Calendar.v3.CalendarService)

    Private Sub ClearAllEvents()

        Dim pageToken As String = Nothing
        Dim events As Events
        Dim qry As New ListRequest(Service, GCalId)

        Do
            qry.PageToken = pageToken
            events = qry.Execute()
            For Each ev As [Event] In events.Items
                Dim dr As New DeleteRequest(Service, GCalId, ev.Id)
                dr.Execute()
            Next
            pageToken = events.NextPageToken
        Loop While Not IsNothing(pageToken)
    End Sub

这篇关于Google日历v3 API [Events:list]请求返回空列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆