首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从google-api-client 0.8.3迁移授权Google::CalendarV3

从google-api-client 0.8.3迁移授权Google::CalendarV3
EN

Stack Overflow用户
提问于 2021-03-18 00:38:37
回答 1查看 29关注 0票数 0

尝试从google-api-client v0.8.3迁移,但找不到Google Calendar集成的这种用例的示例。

应用程序有一个用户模型,允许用户通过Google Outh进行身份验证,并存储Google访问和刷新令牌:

代码语言:javascript
复制
# simplified User class for example
class User
  attr_accessor :access_token
  attr_accessor :refresh_token
end

如何为日历服务对象提供授权?

代码语言:javascript
复制
calendar = Google::Apis::CalendarV3::CalendarService.new
calendar.authorization = ????

ATTEMPT1:使用Google::APIClient::ClientSecrets

代码语言:javascript
复制
s = Google::APIClient::ClientSecrets.new({
  web: {
    access_token: user.access_token,
    refresh_token: user.refresh_token,
    scope: ['https://www.googleapis/auth/calendar.events'],
    client_id: <client id for my app>,
    client_secret: <client secret for my app>
  })
calendar.authorization = s.to_authorization
calendar.list_calendar_lists

结果: Google::Apis::ClientError insufficientPermissions:请求的身份验证范围不足

尝试2:使用Signet::OAuth2::Client

代码语言:javascript
复制
signet = Signet::OAuth2::Client.new( access_token: user.access_token, scope: 'https://www.googleapis/auth/calendar.events' )
calendar.authorization = signet
calendar.list_calendar_lists

结果: Google::Apis::ClientError insufficientPermissions:请求的身份验证范围不足

我使用的访问令牌在v0.8.3版本的代码中工作得很好。谢谢。

EN

回答 1

Stack Overflow用户

发布于 2021-03-18 00:47:53

我的OAuth授权只授权作用域:"https://googleapis/auth/calendar.events",但是列出日历列表的能力需要"https://googleapis/auth/calendar“作用域。

如果作用域正确,上面显示的两种身份验证方法都可以很好地工作。

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

https://stackoverflow.com/questions/66677409

复制
相关文章

相似问题

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