【问题标题】:Access Google Plus Contacts google-api-ruby-client and omniauth-google-oauth2访问 Google Plus 联系人 google-api-ruby-client 和 omniauth-google-oauth2
【发布时间】:2013-12-27 16:52:04
【问题描述】:

我想从 Google Plus 获得联系。 我正在使用

gem "omniauth"
gem "omniauth-google-oauth2"

用于身份验证和

gem "google-api-client"

用于与 google apis 通信。

到目前为止,身份验证工作正常,我在身份验证后获得了 access_token。 现在的问题是我找不到获取我圈子(我的 Google Plus 联系人)中人员列表的方法。

有没有办法做到这一点。

具体来说,我需要知道是否有任何宝石更像谷歌的“fb_graph”?

我发现了这个技巧

https://plus.google.com/u/0/_/socialgraph/lookup/visible/o=%5Bnull%2Cnull%2C%22_UID_%22%5D&rt=j

只需要输入“UID”,你就可以在你的圈子里找到联系人,但只有他们的名字和 ID。但我需要更多信息...

工作流程

client = Google::APIClient.new
client.authorization.client_id = GOOGLE_CONFIG[:app_id]
client.authorization.client_secret = GOOGLE_CONFIG[:app_secret]
client.authorization.access_token = token
plus = client.discovered_api('plus')
data = client.execute( plus.people.list, :collection => 'connected', :userId => 'me').data

在数据中我收到这条消息

<Google::APIClient::Schema::Plus::V1::PeopleFeed:0x6569248 DATA:{"error"=>{"errors"=>[{"domain"=>"global", "reason"=>"insufficientPermissions", "message"=>"Insufficient Permission"}], "code"=>403, "message"=>"Insufficient Permission"}}>

我发现了类似的问题here,但仍然需要找出解决方案。

【问题讨论】:

  • 尝试更改您的 omniauth-google-oauth2 gem 的 scope。您也可以尝试使用新选项:skip_friends =&gt; false
  • @Ashitaka 感谢您的回复。我用了你的建议,但没有运气。我已经更新了我的问题(添加了一些工作流程)。我通过 Google-Omniauth 从 Google 进行身份验证后获得了“令牌”,并希望使用此特定令牌来访问联系人...

标签: ruby-on-rails google-api omniauth google-api-client


【解决方案1】:

我需要在设计初始化程序中添加 Scope,然后通过身份验证令牌,一切似乎都运行良好。

scope: "https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile"

或添加此行

config.omniauth :google_oauth2, GOOGLE_CONFIG[:app_id], GOOGLE_CONFIG[:app_secret],{ access_type: "offline", approval_prompt: "force", scope: 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile', name: 'google'}

【讨论】:

  • 请注意:omniauth-google-oauth2 的自述文件指出“以https://www.googleapis.com/auth/ 开头的范围不需要指定该前缀。”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-09-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-05
相关资源
最近更新 更多