Да, клиент не определен.Попробуйте этот пример кода вместо
https://github.com/googleapis/google-api-ruby-client/blob/master/samples/cli/lib/samples/calendar.rb
и
https://developers.google.com/calendar/quickstart/ruby
Важные части здесь:
require 'google/apis/calendar_v3'
require 'googleauth'
require 'googleauth/stores/file_token_store'
require 'fileutils'
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_READONLY
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)
# figure out your user_id
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
calendar = Google::Apis::CalendarV3::CalendarService.new
calendar.client_options.application_name = APPLICATION_NAME
calendar.authorization = authorize
event = {
summary: 'Events',
attendees: [
{email: 'lpage@example.com'},
{email: 'sbrin@example.com'},
],
start: {
date_time: '2015-05-28T09:00:00-07:00',
time_zone: 'America/Los_Angeles',
},
end: {
date_time: '2015-05-28T17:00:00-07:00',
time_zone: 'America/Los_Angeles',
}
}
event = calendar.insert_event('primary', event, send_notifications: true)
ине забудьте сначала выполнить это:
gem install google-api-client
, а также создать эти файлы с правильной аутентификационной информацией
credentials.json
token.yaml
и выяснить ваш user_id
.