I am trying to find all the freebusy times from my primary calendar using the "query_freebusy" method but I am receiving a "not found" error as a response
I admit I am a novice coder at best, but so far I've been using much of the code from the quickstart-example in the google calendar API documentation to authorize my requests, as well as code from another stack overflow page regarding the query_freebusy method. My code is as follows:
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
The response I get is:
{"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"}
I have 5 events on that calendar between that time frame, but none show up in the response.