Пример #1
0
	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;
	}
Пример #2
0
	private void getInfo(RenrenApiClient apiClient) {
		if (up.size()!=0){
			Set<String>	messages = new HashSet<String>();
			UserSpace t = up.poll();
			String sessionKey = t.getSessionKey();
			String renrenUserId = t.getRenrenUserId();
			message = t.getMessage();
			
			messages.addAll(message); //保证接收过来的信息也在用户空间中
			//refreshToken()			  //刷新token 保证token有效
			
			JSONArray feedInfo = new JSONArray();
			try {
			feedInfo = apiClient.getFeedService().getFeed("10", Integer.parseInt(renrenUserId), 1, 10,new AccessToken(sessionKey));
						
			if (feedInfo != null && feedInfo.size()>0) {
		
				for (int i=0;i<feedInfo.size();i++)
				{
					JSONObject currentFeed = (JSONObject) feedInfo.get(i);

					if (currentFeed != null){
						String message = (String) currentFeed.get("message");
						messages.add(message);
						System.out.println("[FeedStub : run]: "+"messsage: "+message);
						if (!this.message.contains(message)){
							Map<String,String> map = new HashMap();
							map.put("message", URLEncoder.encode(message));
							map.put("from",URLEncoder.encode("renren"));
							try {
								config.properties.irt.send(t.getToken(),"updatestatus", map);
							} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
							}
							System.out.println("[FeedStub : run]: "+"messsage: "+message);
						}
					}
				}
			}
			t.updateMessage(messages);
			if (!up.offer(t)) System.out.println("[FeedStub : run] Memery Out");
			} catch(Exception e){
				//获取info错误,用户退出
			}
		}
	}