Google API ruby客户端显然不能获取所有事件

Google API ruby客户端显然不能获取所有事件,ruby,google-api-ruby-client,Ruby,Google Api Ruby Client,我使用Github上的GoogleAPI Ruby客户端作为日历应用程序的起点 它运行良好,通常没有问题。然而,最近我注意到我的应用程序在生产中并没有获取所有事件。在通过ruby客户端请求了一些日历之后,我在一个表中呈现事件。在我的第一次通话中,只有我用我的应用程序生成的日期,根本没有从日历中获取任何数据。在第二次请求时,一些日历将返回数据,并重新加载应用程序几次,所有日历将返回事件 所以在我看来,似乎有一些缓存正在进行。如果数据返回速度不够快,将向我发送一个空响应。再次请求发送一些数据,请求越

我使用Github上的GoogleAPI Ruby客户端作为日历应用程序的起点

它运行良好,通常没有问题。然而,最近我注意到我的应用程序在生产中并没有获取所有事件。在通过ruby客户端请求了一些日历之后,我在一个表中呈现事件。在我的第一次通话中,只有我用我的应用程序生成的日期,根本没有从日历中获取任何数据。在第二次请求时,一些日历将返回数据,并重新加载应用程序几次,所有日历将返回事件

所以在我看来,似乎有一些缓存正在进行。如果数据返回速度不够快,将向我发送一个空响应。再次请求发送一些数据,请求越多,返回的数据越多

可能是我的设置有问题,我认为不完美:

get '/' do
  #fetch all calendars
  result = api_client.execute(:api_method => calendar_api.calendar_list.list,
                              :authorization => user_credentials)
  cals = result.data.items.map do |i|
    #skip id calendar does not belong to owner or is the "private" primary one
    next if i.primary || i.accessRole != "owner"
    i.summary
  end
  cals.compact!
  #save all users mentioned in calendars in a set
  events_list = result.data.items.map do |i|
    #skip calendar if primary or not owned by user (cannot be changed anyway)
    next if i.primary || i.accessRole != "owner"
    r = api_client.execute(:api_method => calendar_api.events.list,
                           :parameters => {'calendarId' => i.id},
                           :timeMax => DateTime.now.next_month,
                           :timeMin => DateTime.now.beginning_of_month)
    #capture all calendars and their events and map it to an Array
    r.data.items.delete_if { |item| item.status == "cancelled" }
  end
  #remove skipped entries (=nil)
  events_list.compact! 
  slim :home, :locals => { :title => Konfig::TITLE, :events_list => events_list, :cals => cals}
end

顺便说一句:timeMax和:timeMin也没有按预期工作,但我想这是一个不同的问题。

代码似乎不是这里的问题

我猜下面的一种情况正在发生

  • 你是被限制的吗?(不太可能用一个简单的应用程序达到极限,但仍然很容易用响应代码检查)
  • 加载时间超过2秒(默认的net http响应超时为2秒,默认的法拉第设置为net:http)
  • 在这种情况下我该怎么办。在决定下一步行动之前,我会做以下几点

  • 从api客户端gem的响应对象打印响应对象错误代码和http头。我将寻找响应中的缓存头和状态代码

  • 如果您的生产机器上有ngrep,只需让它打印并显示整个http请求响应,而不是在gem中打印

  • 如果响应时间超过2秒,请增加net::http的超时设置并检查


  • 谢谢。我真的无法复制我自己的错误,但你的答案对我来说很有意义,所以我想我会给你50分:)