我正在尝试使用“ query_freebusy”方法从我的主日历中查找所有空闲时间,但我收到“未找到”错误作为响应
我承认我充其量只是一名新手,但到目前为止,我一直在使用google calendar API文档中quickstart-example的许多代码来授权我的请求以及其他堆栈的代码关于query_freebusy方法的page溢出。 我的代码如下:
require 'google/apis/calendar_v3'
require 'googleauth'
require 'googleauth/stores/file_token_store'
require 'date'
require 'fileutils'
require 'pry'
require 'pp'
OOB_URI = 'urn:ietf:wg:oauth:2.0:oob'.freeze
APPLICATION_NAME = 'Google Calendar API Ruby Quickstart'.freeze
CREDENTIALS_PATH = 'credentials.json'.freeze
TOKEN_PATH = 'token.yaml'.freeze
SCOPE = Google::Apis::CalendarV3::AUTH_CALENDAR
def authorize
client_id = Google::Auth::ClientId.from_file(CREDENTIALS_PATH)
token_store = Google::Auth::Stores::FileTokenStore.new(file: TOKEN_PATH)
authorizer = Google::Auth::UserAuthorizer.new(client_id, SCOPE, token_store)
user_id = 'default'
credentials = authorizer.get_credentials(user_id)
if credentials.nil?
url = authorizer.get_authorization_url(base_url: OOB_URI)
puts 'Open the following URL in the browser and enter the ' \
"resulting code after authorization:\n" + url
code = gets
credentials = authorizer.get_and_store_credentials_from_code(
user_id: user_id, code: code, base_url: OOB_URI
)
end
credentials
end
service = Google::Apis::CalendarV3::CalendarService.new
service.client_options.application_name = APPLICATION_NAME
service.authorization = authorize
calendar_id = 'primary'
body = Google::Apis::CalendarV3::FreeBusyRequest.new
body.items = [calendar_id]
body.time_min = "2019-04-28T00:00:00-00:00"
body.time_max = "2019-04-30T00:00:00-00:00"
response = service.query_freebusy(body)
puts response.to_json
我得到的答复是:
{"calendars":{"":{"busy":[],"errors":[{"domain":"global","reason":"notFound"}]}},"kind":"calendar#freeBusy","timeMax":"2019-04-30T00:00:00.000+00:00","timeMin":"2019-04-28T00:00:00.000+00:00"}
在该时间段内,该日历上有5个事件,但响应中未显示任何事件。