gpt4 book ai didi

ruby-on-rails - 访问 Google Plus 通讯录 google-api-ruby-client 和 omniauth-google-oauth2

转载 作者:行者123 更新时间:2023-12-04 05:39:19 25 4
gpt4 key购买 nike

我想与 Google Plus 取得联系。我正在使用

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

用于身份验证和

gem "google-api-client"

用于与 google api 通信。

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

有没有办法做到这一点。

具体来说,我需要知道是否有任何 gem 更像 google 的“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但仍然需要找出解决方案。

最佳答案

我需要在设计初始值设定项中添加 Scope,然后通过身份验证 token ,一切似乎都运行良好。

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'}

关于ruby-on-rails - 访问 Google Plus 通讯录 google-api-ruby-client 和 omniauth-google-oauth2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20804490/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com