use*_*712 11 ruby api ruby-on-rails http
我正在尝试使用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)
Run Code Online (Sandbox Code Playgroud)
小智 34
您正在请求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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12005 次 |
| 最近记录: |