在点击Google Contacts API时出现“按对等方重置连接”错误

我正在尝试使用Google Contacts API将Google Contacts添加到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)