gpt4 book ai didi

ruby-on-rails - Google 联系人 API 401 错误 RestClient::Unauthorized

转载 作者:太空宇宙 更新时间:2023-11-03 16:53:08 25 4
gpt4 key购买 nike

我想使用 Restclient 在 Ruby on rails 中检索用户的 Google 联系人,但每次尝试时,我的查询行都会遇到 Restclient 401 Unauthorized 错误。我认为我的查询是错误的或错过了什么,但我没有在 Google Contact API 文档中找到任何有用的东西。有什么想法吗?

这是我的范围

scope = 'https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile+https://www.google.com/m8/feeds/contacts/default/full/+https://mail.google.com/mail/feed/atom/+https://www.googleapis.com/auth/calendar'

这是我用新收到的 access_token 调用的方法

def import_google_contact(user_email, access_token)
r = RestClient.get "https://www.google.com/m8/feeds/contacts/#{user_email}/full?access_token=#{access_token}"
...
end

这很奇怪,因为我之前设法使用此请求以相同的方法获取用户电子邮件

r = RestClient.get "https://www.googleapis.com/oauth2/v2/userinfo?access_token=#{access_token}"

最佳答案

我发现我没有在请求联系人数据的范围内放置正确的参数?我把它换成了

https://www.google.com/m8/feeds

这很奇怪,因为 Google 在授权过程中接受了一个错误

关于ruby-on-rails - Google 联系人 API 401 错误 RestClient::Unauthorized,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16528286/

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