Created
June 4, 2010 08:05
-
-
Save marshluca/425135 to your computer and use it in GitHub Desktop.
使用json,net/http解析人人API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "net/http" | |
require "json" | |
USER = '[email protected]' | |
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