撒也不说直接上代码:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.xiaonei.api.*"%>
<%@ page import="java.net.*"%>
<%@ page import="com.xiaonei.api.schema.*,org.w3c.dom.Document"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>RenRen Test</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="flash game">
<meta http-equiv="description" content="This is Api Test.">
</head>
<body>
<%
String sessionKey=request.getParameter("xn_sig_session_key");
//out.println("sessionKey:"+sessionKey);
if(sessionKey==null)
{
//如果用户是第一次添加该应用则引导用户授权,否则无法获取sessionid
String url="http://app.renren.com/apps/tos.do?v=1.0&api_key=63b91f609ad14388a0e1238fe8769d4f&next=http://apps.renren.com/****/";//***替换为你的应用地址
response.sendRedirect(url);
return;
}
XiaoneiRestClient client = new XiaoneiRestClient(appkey,secret key,sessionKey
//client.friends_get();//获得好友列表
//FriendsGetResponse resp = (FriendsGetResponse)client.getResponsePOJO();//处理返回结果
//List<Integer> list = resp.getUid();
//for (Integer uid : list) {
//}
int uid=client.users_getLoggedInUser();//当前用户ID
out.println("uid:"+uid+"<br>");
try{
EnumSet<ProfileField> enumFields = EnumSet.of(ProfileField.NAME,
ProfileField.HOMETOWN_LOCATION,ProfileField.BIRTHDAY,
ProfileField.HEADURL,ProfileField.MAINURL,
ProfileField.SEX,ProfileField.STAR,ProfileField.TINYURL,
ProfileField.ZIDOU,ProfileField.UNIVERSITY_HISTORY,
ProfileField.WORK_HISTORY);//声明所需用户属性
Document doc = client.users_getInfo(uid, enumFields);//获取指定ID用户的信息
UsersGetInfoResponse loggedUserGetInfoRes = (UsersGetInfoResponse) client.getResponsePOJO();//处理返回结果
List<User> lu=loggedUserGetInfoRes.getUser();
for(User u:lu)
{
out.println(u.getName()+"<br>");
}
}catch(Exception e)
{
out.println("ERROR:"+e.toString());
}
%>
</body>
</html>