我希望在我的日历中某些用户的操作之后插入事件。这就是为什么我希望在Google中使用服务器对服务器的授权。我写了下一段代码:
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)但是当我尝试使用那个代码时,我得到了下一个答案:
cannot load such file -- google/api_client (LoadError)我理解,也许我必须使用以前版本的gem (<0.9)来消除这个错误。但是不知道如何使insert事件具有<0.9GoogleAPI版本的语法。
发布于 2016-08-04 13:19:19
我找到了解决办法。
使用api v.0.8.2并参见下一页:Rails + Google Calendar API events not created
https://stackoverflow.com/questions/38763190
复制相似问题