我正在处理管理Facebook页面的应用程序。我必须在此页面上加载私人对话。我为此目的使用restfb graph api。我尝试了一些例子,但它们没有用。以下是我正在尝试供您参考的代码。
Connection<Conversation> conversations = facebookClient.fetchConnection("me/conversations", Conversation.class);
for(List<Conversation> conversationPage : conversations) {
for(Conversation conversation : conversationPage) {
System.out.println(conversation);
System.out.println(conversation.getUnreadCount());
Message lastMessage = null;
for (Message message : conversation.getMessages())
{
System.out.println("Message text = " + message.getMessage());
System.out.println("Message unread = " + message.getUnread());
System.out.println("Message from = " + message.getFrom().getName());
System.out.println("Message to = " + message.getTo().get(0).getName());
System.out.println("Message unseen = " + message.getUnseen());
lastMessage = message;
}
}
}
但它在
给我0消息计数的System.out.println(conversation.getUnreadCount());
虽然我在我的页面上管理了未读消息。我需要您的帮助才能解决此问题。请指教。
答案 0 :(得分:2)
感谢CBroe,感谢您的帮助。我通过调试facebook graph api得到了答案。这是我用过的代码。
Connection<Conversation> conversations = facebookClient.fetchConnection("me/conversations", Conversation.class);
for(List<Conversation> conversationPage : conversations) {
for(Conversation conversation : conversationPage) {
String id = conversation.getId();
Connection<Message> messages = facebookClient.fetchConnection(id + "/messages", Message.class, Parameter.with("fields", "message,created_time,from,id"));
}
}