问题
I want to get contact from Google Plus. I am using
gem "omniauth"
gem "omniauth-google-oauth2"
for authentication and
gem "google-api-client"
for comunicate with google apis.
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.
Specifically I need to know is there any gem more like "fb_graph" for google?
I found this trick
https://plus.google.com/u/0/_/socialgraph/lookup/visible/o=%5Bnull%2Cnull%2C%22_UID_%22%5D&rt=j
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.
回答1:
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"
OR Add this line
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'}
来源:https://stackoverflow.com/questions/20804490/access-google-plus-contacts-google-api-ruby-client-and-omniauth-google-oauth2