首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >服务器到服务器Rails

服务器到服务器Rails
EN

Stack Overflow用户
提问于 2016-08-04 09:13:19
回答 1查看 454关注 0票数 3

我希望在我的日历中某些用户的操作之后插入事件。这就是为什么我希望在Google中使用服务器对服务器的授权。我写了下一段代码:

代码语言:javascript
复制
require 'google/apis/calendar_v3'
require 'googleauth'

require 'google/api_client/client_secrets'
require 'google/api_client'

初始化客户端

代码语言:javascript
复制
client = Google::Apis::CalendarV3::CalendarService.new

加载和解密私钥

代码语言:javascript
复制
key = G.load_from_pkcs12('google_secrets.json', 'notasecret')

生成请求主体以进行授权

代码语言:javascript
复制
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)

获取访问令牌

代码语言:javascript
复制
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)

但是当我尝试使用那个代码时,我得到了下一个答案:

代码语言:javascript
复制
cannot load such file -- google/api_client (LoadError)

我理解,也许我必须使用以前版本的gem (<0.9)来消除这个错误。但是不知道如何使insert事件具有<0.9GoogleAPI版本的语法。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-04 13:19:19

我找到了解决办法。

使用api v.0.8.2并参见下一页:Rails + Google Calendar API events not created

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38763190

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档