NameValuePair[] fixedParam = {
new NameValuePair("method", "xiaonei.users.getInfo"),
new NameValuePair("v", "1.0"),
new NameValuePair("api_key", apikey),
new NameValuePair("session_key", sessionkey),
new NameValuePair("fields",field ),
new NameValuePair("uids", uid)
};
post.addParameters(fixedParam);
client.executeMethod(post);
String s = post.getResponseBodyAsString();
StringReader read = new StringReader(s);
//創(chuàng)建新的輸入源SAX 解析器將使用 InputSource 對象來確定如何讀取 XML 輸入
InputSource source = new InputSource(read);
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(source);
Element foo = doc.getRootElement();
Namespace ns = foo.getNamespace();
List allChildren = foo.getChildren();
String info = ((Element)allChildren.get(0)).getChild(field,ns).getText();
if(field.equals("province")){
String province = ((Element)allChildren.get(0)).getChild("hometown_location",ns).getChild("province",ns).getText();
return province;
}
if(field.equals("city")){
String city = ((Element)allChildren.get(0)).getChild("hometown_location",ns).getChild("city",ns).getText();
return city;
}
return info;
}
//編碼轉(zhuǎn)換
public static class UTF8PostMethod extends PostMethod {
public UTF8PostMethod(String url) {
super(url);
}
@Override
public String getRequestCharSet() {
//return super.getRequestCharSet();
return "UTF-8";
}
}
//獲取用戶姓名
public String getName(String uid) throws HttpException, IOException, JDOMException{
String name = this.getStream(uid, "name");
return name;
}
//獲取用戶性別 true是男
public boolean getSex(String uid) throws HttpException, IOException, JDOMException{
String sex = this.getStream(uid, "sex");
if(sex.equals("1"))
return true;
else
return false;
}
//獲取用戶生日 格式:yyyy-MM-dd
public String getBirthday(String uid) throws HttpException, IOException, JDOMException{
String birthday = this.getStream(uid, "birthday");
return birthday;
}
//判斷用戶是否為星級用戶 true 為是
public boolean isStar(String uid) throws HttpException, IOException, JDOMException{
String star = this.getStream(uid, "star");
if(star.equals("1"))
return true;
else
return false;
}
//獲取用戶小圖url
public String getTinyurl(String uid) throws HttpException, IOException, JDOMException{
String tinyurl = this.getStream(uid, "tinyurl");
return tinyurl;
}
//獲取用戶標(biāo)準(zhǔn)頭像圖片url
public String getHeadurl(String uid) throws HttpException, IOException, JDOMException{
String headurl = this.getStream(uid, "headurl");
return headurl;
}
//獲取用戶家鄉(xiāng)所 省
public String getProvince(String uid) throws HttpException, IOException, JDOMException{
String province = this.getStream(uid, "province");
return province;
}
//獲取用戶家鄉(xiāng)所在城市
public String getCity(String uid) throws HttpException, IOException, JDOMException{
String city = this.getStream(uid, "city");
return city;
}
}