访问 Google Plus 联系人 google-api-ruby-client 和 omniauth-google-



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

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

用于身份验证和

gem "google-api-client"

用于与谷歌 API 通信。

到目前为止,身份验证工作正常,身份验证后我得到了access_token。现在的问题是我找不到一种方法来获取我的圈子里的人(我的谷歌加联系人)。

有什么办法可以做到这一点。

具体来说,我需要知道谷歌是否有更像"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"}}>

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

我需要在设计初始化项中添加 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'}

最新更新