Skip to content

Instantly share code, notes, and snippets.

@marshluca
Created June 4, 2010 08:05
Show Gist options
  • Save marshluca/425135 to your computer and use it in GitHub Desktop.
Save marshluca/425135 to your computer and use it in GitHub Desktop.
使用json,net/http解析人人API
require "net/http"
require "json"
USER = 'marshluca@163.com'
PASS = '123456'
API_URL = "http://api.renren.com/restserver.do"
def base_params
{
"api_key" => "f2570a570d56439784bfb69dbda699d1",
"call_id" => "",
"sig" => "",
"v" => "1.0",
"session_key" => "",
"format" => "json",
}
end
def parse_api(params)
uri = URI.parse(API_URL)
request = Net::HTTP::Post.new(uri.request_uri)
request.basic_auth(USER,PASS)
request.set_form_data(base_params.merge(params))
http = Net::HTTP.new(uri.host, uri.port)
response = http.request(request)
JSON.parse(response.body)
end
puts parse_api({"method" => "users.getInfo", "uids" => "89494763"})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment