分页获取聊天记录的结果条数不对
String currentTimestamp = String.valueOf(System.currentTimeMillis());
ObjectNode queryStrNode2 = factory.objectNode();
queryStrNode2.put("ql", "select * where timestamp<" + currentTimestamp);
queryStrNode2.put("limit", "10");
// 第一页
ObjectNode messages2 = getChatMessages(queryStrNode2);
System.out.println("-------------"+messages2);
// 第二页
String cursor = messages2.get("cursor").asText();
queryStrNode2.put("cursor", cursor);
ObjectNode messages3 = getChatMessages(queryStrNode2);
System.out.println("+++++++++++++"+messages3);
第一页返回的数据条数count是9,第二页返回的数据条数count是10,为啥会不一样?
ObjectNode queryStrNode2 = factory.objectNode();
queryStrNode2.put("ql", "select * where timestamp<" + currentTimestamp);
queryStrNode2.put("limit", "10");
// 第一页
ObjectNode messages2 = getChatMessages(queryStrNode2);
System.out.println("-------------"+messages2);
// 第二页
String cursor = messages2.get("cursor").asText();
queryStrNode2.put("cursor", cursor);
ObjectNode messages3 = getChatMessages(queryStrNode2);
System.out.println("+++++++++++++"+messages3);
第一页返回的数据条数count是9,第二页返回的数据条数count是10,为啥会不一样?
没有找到相关结果
已邀请:
4 个回复
beyond - imgeek运营
把第一页的数据发出来看一下呢,主要是看
"limit": [
"10"
]
"count": 10
这里
确定写的limit 10 ,而返回来 "count": 是9
林加富
ObjectNode queryStrNode2 = factory.objectNode();
queryStrNode2.put("ql", "select * where timestamp<" + currentTimestamp);
queryStrNode2.put("limit", "10");
2、String currentTimestamp = String.valueOf(System.currentTimeMillis());
ObjectNode queryStrNode2 = factory.objectNode();
queryStrNode2.put("limit", "10");
3、String currentTimestamp = String.valueOf(System.currentTimeMillis());
ObjectNode queryStrNode2 = factory.objectNode();
queryStrNode2.put("ql", "select * where timestamp<" + currentTimestamp);
4、String currentTimestamp = String.valueOf(System.currentTimeMillis());
ObjectNode queryStrNode2 = factory.objectNode();
林加富
林加富
* REST API Demo : 聊天消息导出REST API HttpClient4.3实现
*
* Doc URL: http://www.easemob.com/docs/rest/chatmessage/
*
* @author Lynch 2014-09-15
*
*/
public class EasemobChatMessage {
private static final Logger LOGGER = LoggerFactory.getLogger(EasemobChatMessage.class);
private static final JsonNodeFactory factory = new JsonNodeFactory(false);
private static final String APPKEY = Constants.APPKEY;
// 通过app的client_id和client_secret来获取app管理员token
private static Credential credential = new ClientSecretCredential(Constants.APP_CLIENT_ID,
Constants.APP_CLIENT_SECRET, Roles.USER_ROLE_APPADMIN);
/**
* Main Test
*
* @param args
*/
public static void main(String args) {
// 聊天消息 获取最新的20条记录
// ObjectNode queryStrNode = factory.objectNode();
// queryStrNode.put("ql", "select+*+where+from='111'+and+to='333'");
// queryStrNode.put("limit", "10");
// queryStrNode.put("cursor", "NjQzMjIwMzYyOmdHa0FBUUVBZ0hNQUF6RXhNUUNBZFFBUTR4d2JDc0NKRWVTNkRPWEk2NEhHeWdDQWRRQVE0eHdiQU1DSkVlU3pzZVZEYVhnMnZRQQ");
// ObjectNode messages = getChatMessages(queryStrNode);
// System.out.println("=====================================" + messages);
// 聊天消息 获取7天以内的消息
// String currentTimestamp = String.valueOf(System.currentTimeMillis());
// String senvenDayAgo = String.valueOf(System.currentTimeMillis() - 365 * 24 * 60 * 60 * 1000);
// ObjectNode queryStrNode1 = factory.objectNode();
// queryStrNode1.put("ql", "select * where timestamp>" + "1425011630720" + " and timestamp<" + currentTimestamp);
//?ql=select * where timestamp>1403164734226&limit=10&cursor=**
// queryStrNode1.put("ql", "select * where timestamp<" + currentTimestamp);
// queryStrNode1.put("limit", "1000");
// ObjectNode messages1 = getChatMessages(queryStrNode1);
// System.out.println("=====================================" + messages1);
// 聊天消息 分页获取
String currentTimestamp = String.valueOf(System.currentTimeMillis());
ObjectNode queryStrNode2 = factory.objectNode();
queryStrNode2.put("ql", "select * where timestamp<" + currentTimestamp);
// queryStrNode2.put("ql", "select+*+where+from='111'+and+to='333'");
queryStrNode2.put("limit", "10");
// 第一页
ObjectNode messages2 = getChatMessages(queryStrNode2);
System.out.println("-------------"+messages2);
// // 第二页
// String cursor = messages2.get("cursor").asText();
// queryStrNode2.put("cursor", cursor);
// ObjectNode messages3 = getChatMessages(queryStrNode2);
// System.out.println("+++++++++++++"+messages3);
}
/**
* 获取聊天消息
*
* @param queryStrNode
*
*/
public static ObjectNode getChatMessages(ObjectNode queryStrNode) {
ObjectNode objectNode = factory.objectNode();
// check appKey format
if (!HTTPClientUtils.match("^(?!-)[0-9a-zA-Z\\-]+#[0-9a-zA-Z]+", APPKEY)) {
LOGGER.error("Bad format of Appkey: " + APPKEY);
objectNode.put("message", "Bad format of Appkey");
return objectNode;
}
try {
String rest = "";
if (null != queryStrNode && queryStrNode.get("ql") != null && !StringUtils.isEmpty(queryStrNode.get("ql").asText())) {
rest = "ql="+ java.net.URLEncoder.encode(queryStrNode.get("ql").asText(), "utf-8");
}
if (null != queryStrNode && queryStrNode.get("limit") != null && !StringUtils.isEmpty(queryStrNode.get("limit").asText())) {
rest = rest + "&limit=" + queryStrNode.get("limit").asText();
}
if (null != queryStrNode && queryStrNode.get("cursor") != null && !StringUtils.isEmpty(queryStrNode.get("cursor").asText())) {
rest = rest + "&cursor=" + queryStrNode.get("cursor").asText();
}
// URL chatMessagesUrl = HTTPClientUtils.getURL(Constants.APPKEY.replace("#", "/") + "/chatmessages?" + rest);
URL chatMessagesUrl = HTTPClientUtils.getURL(Constants.APPKEY.replace("#", "/") + "/chatmessages?" + rest);
objectNode = HTTPClientUtils.sendHTTPRequest(chatMessagesUrl, credential, null, HTTPMethod.METHOD_GET);
} catch (Exception e) {
e.printStackTrace();
}
return objectNode;
}
}