Google API ruby 客户端显然无法获取所有事件

问题描述 投票:0回答:1

我使用了 Github 上的 Google API 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 也没有按预期工作,但我认为这是一个不同的问题。

ruby google-api-ruby-client
1个回答
2
投票

代码似乎不是这里的问题。

我猜测正在发生以下情况之一

  1. 您受到费率限制吗? (不太可能达到使用简单应用程序的限制,但仍然很容易使用响应代码进行检查)
  2. 加载时间超过 2 秒(默认网络 http 响应超时为 2 秒,默认法拉第设置为 net:http)

在这种情况下我会怎么做。在决定下一步之前我会做以下事情

  1. 从其响应对象打印 api 客户端 gem 中的响应对象错误代码和 http 标头。我会寻找响应中的缓存标头是什么以及状态代码是什么。

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

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

© www.soinside.com 2019 - 2024. All rights reserved.