@RequestMapping(value = "/home") public String home(ModelMap modelMap) { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); System.out.println("HomeController: passing through..."); System.out.println("获取相关renren参数"); String sessionKey = request.getParameter("xn_sig_session_key"); String renrenUserId = request.getParameter("xn_sig_user"); System.out.println("Session Key: " + sessionKey); System.out.println("renrenUserId: " + renrenUserId); if (sessionKey != null && renrenUserId != null) { RenrenApiClient apiClient = new RenrenApiClient(sessionKey); SessionKey sessionKeyReal = new SessionKey(sessionKey); // 获取用户信息 JSONArray userInfo = apiClient.getUserService().getInfo(renrenUserId, sessionKeyReal); if (userInfo != null && userInfo.size() > 0) { JSONObject currentUser = (JSONObject) userInfo.get(0); if (currentUser != null) { String userName = (String) currentUser.get("name"); String userHead = (String) currentUser.get("headurl"); request.setAttribute("userName", userName); request.setAttribute("userHead", userHead); } } JSONArray friends = apiClient.getFriendsService().getFriends(2, 80, sessionKeyReal); String friendsStr = friends.toJSONString().replace("\"", "\'"); request.setAttribute("friends", friendsStr); } // 测试commit modelMap.addAttribute("welcome", "Walter's APP"); return "home"; }
public Boolean addFeedUser(String sessionKey,String token){ RenrenApiClient apiClient = RenrenApiClient.getInstance(); JSONArray feedInfo = new JSONArray(); String renrenUserId; try { renrenUserId = String.valueOf(apiClient.getUserService().getLoggedInUser(new AccessToken(sessionKey))); } catch (Exception err){ err.printStackTrace(); return false; } try { feedInfo = apiClient.getFeedService().getFeed("10", Integer.parseInt(renrenUserId), 1, 30,new AccessToken(sessionKey)); //可能拿不到 } catch (Exception err){ err.printStackTrace(); return false; } Set<String> messages = new HashSet<String>(); if (feedInfo != null && feedInfo.size()>0) { for (int i=0;i<feedInfo.size();i++) { JSONObject currentFeed = (JSONObject) feedInfo.get(i); assert (currentFeed != null); String message = (String) currentFeed.get("message"); messages.add(message); } } UserSpace t = new UserSpace(sessionKey,renrenUserId,messages,token); if (!up.offer(t)) return false; ApiInitListener.User.put(config.properties.irt.getUserIdByToken(token),t); return true; }