加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 点击Google Contacts API时发现“由对等连接重

发布时间:2020-12-16 21:59:58 所属栏目:百科 来源:网络整理
导读:我试图使用Google Contacts API将Google通讯录拉入Rails应用程序.我已经完成了Oauth2握手,现在我使用我的访问令牌来请求受保护的资源.这是代码: uri = URI('https://www.google.com/m8/feeds/contacts/default/full')params = { :client_id = APP_CONFIG[:g
我试图使用Google Contacts API将Google通讯录拉入Rails应用程序.我已经完成了Oauth2握手,现在我使用我的访问令牌来请求受保护的资源.这是代码:
uri = URI('https://www.google.com/m8/feeds/contacts/default/full')
params = { :client_id => APP_CONFIG[:google_api_client_id],:access_token => auth.access_token,"max-results".to_sym => max_results
         }

uri.query = URI.encode_www_form(params)
res = Net::HTTP.get_response(uri)

解决方法

您正在请求HTTPS资源,因此您的GET请求需要使用SSL加密.

http://ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/Net/HTTP.html#method-i-use_ssl-3F

所以你的最后一行应该是:

http = Net::HTTP.new(uri.host,uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE # You should use VERIFY_PEER in production
  request = Net::HTTP::Get.new(uri.request_uri)
  res = http.request(request)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读