2
我想在用户的某些操作后在我的日历中插入事件。这就是为什么我想要使用Google API的服务器到服务器授权。我写了下面的代码:Google Calendar API服务器到服务器Rails
require 'google/apis/calendar_v3'
require 'googleauth'
require 'google/api_client/client_secrets'
require 'google/api_client'
初始化客户端
client = Google::Apis::CalendarV3::CalendarService.new
负荷和解密私钥
key = G.load_from_pkcs12('google_secrets.json', 'notasecret')
生成请求主体授权
client.authorization = Signet::OAuth2::Client.new(
:token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
:audience => 'https://accounts.google.com/o/oauth2/token',
:scope => 'https://www.googleapis.com/auth/calendar',
:issuer => '....',
:signing_key => key)
获取访问令牌
client.authorization.fetch_access_token!
# load API definition
service = client.discovered_api('calendar', 'v3')
# there is a place for variable "event" declaration
client.execute(:api_method => service.event.insert,
:parameters => { '....' => 'primary' },
:event => event)
但是当我尝试使用的代码,我recive下一个答案:
cannot load such file -- google/api_client (LoadError)
我明白,也许我必须用宝石的以前版本的谷歌API的客户端(< 0.9)为了摆脱那个错误。但不知道我必须如何使用< 0.9 google api版本的语法来插入事件。