Но каким-то образом API графиков Facebook ограничивает количество комментариев до 25, поскольку мое приложение аварийно завершает работу с «Исключение в потоке «main» java.lang.IndexOutOfBoundsException: Индекс: 25, Размер: 25»
Я использую пейджинг и fetchNext , но он все равно не работает .
Вот мой код —
Код: Выделить всё
public class Facebooktest {
static Facebook facebook;
public static void main(String[] args) throws FacebookException, IOException {
// Make the configuration builder
ConfigurationBuilder confBuilder = new ConfigurationBuilder();
confBuilder.setDebugEnabled(true);
// Set application id, secret key and access token
confBuilder.setOAuthAppId("MyID");
confBuilder.setOAuthAppSecret("MyAppSecret");
confBuilder.setOAuthAccessToken("MyAccessToken");
// Set permission
confBuilder.setOAuthPermissions("email,publish_stream, id, name, first_name, last_name, generic");
confBuilder.setUseSSL(true);
confBuilder.setJSONStoreEnabled(true);
// Create configuration object
Configuration configuration = confBuilder.build();
// Create facebook instance
FacebookFactory ff = new FacebookFactory(configuration);
facebook = ff.getInstance();
ResponseList
results = facebook.getPosts("narendramodi");
//facebook.getFriends(new Reading().fields("gender"));
/*System.out.println("success");
System.out.println(facebook.getMe().getFirstName());*/
String userId="";
for (Post post : results) {
System.out.println(post.getMessage() +"===="+ + post.getSharesCount() +"====="+ post.getLikes().size()); // Gives a max of 25 likes
List userComments = getComments(post);
for (int j = 0; j < userComments.size(); j++) {
userId=post.getComments().get(j).getFrom().getId();
User user = facebook.getUser(userId);
System.out.println(user.getFirstName() + "---- "+ post.getComments().get(j).getLikeCount() +"---- "+ user.getHometown() + "======" + userComments.get(j).getMessage());
}
}
}
public static List getComments(Post post) {
List fullComments = new ArrayList();
try {
PagableList comments = post.getComments();
Paging paging;
do {
for (Comment comment: comments)
fullComments.add(comment);
paging = comments.getPaging();
} while ((paging != null) &&
((comments = facebook.fetchNext(paging)) != null));
} catch (FacebookException ex) {
Logger.getLogger(Facebook.class.getName())
.log(Level.SEVERE, null, ex);
}
return fullComments;
}
}
Поскольку эта часть кода (post.getLikes().size()) дает максимум 25 лайков!
Заранее спасибо
Подробнее здесь: https://stackoverflow.com/questions/272 ... -on-a-post
Мобильная версия