访问Google Plus联系人google-api-ruby-client和omniauth-google-oauth2 [英] Access Google Plus Contacts google-api-ruby-client and omniauth-google-oauth2
问题描述
我想与Google Plus联系。
我正在使用
I want to get contact from Google Plus. I am using
gem "omniauth"
gem "omniauth-google-oauth2"
用于身份验证和
gem "google-api-client"
用于与Google apis通信。
for comunicate with google apis.
到目前为止,身份验证工作正常,在验证后我获得了 access_token 。
现在的问题是我无法找到一种方法来获取我的圈子中的人员名单(我的Google Plus联系人)。
So far authentication is working fine and I got access_token after authentication. Now problem is I couldn't find a way to get list of people in my circle (My Google Plus Contact).
有什么方法可以做这是。
Is there any way to do this.
具体而言,我需要知道是否有任何宝石更像fb_graphfor google?
Specifically I need to know is there any gem more like "fb_graph" for google?
I找到了这个把戏
https://plus.google.com/u/0/_/socialgraph/lookup/visible/o=%5Bnull%2Cnull%2C%22_UID_%22%5D&rt=j
UID,您可以在您的圈子中获取联系人,但只能使用他们的姓名和ID。但我需要更多信息......
Just need to put "UID" and you can get contacts in your circle but their name and ID only. But I need more information...
WorkFlow
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
在数据中,我收到此消息
In data I get this message
<Google::APIClient::Schema::Plus::V1::PeopleFeed:0x6569248 DATA:{"error"=>{"errors"=>[{"domain"=>"global", "reason"=>"insufficientPermissions", "message"=>"Insufficient Permission"}], "code"=>403, "message"=>"Insufficient Permission"}}>
我发现了类似的问题,但解决方案仍然需要找出。
I found similar problem here but solution is still needs to be find out.
推荐答案
我需要在设计初始化器中添加作用域,然后通过auth令牌,一切看起来都很完美。
I need to add Scope in devise initializers and then by auth token everything seems to be working perfectly.
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'}
这篇关于访问Google Plus联系人google-api-ruby-client和omniauth-google-oauth2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!