diff --git a/backmeup-facebook-plugin/src/main/java/org/backmeup/facebook/htmlgenerator/HTMLGenerator.java b/backmeup-facebook-plugin/src/main/java/org/backmeup/facebook/htmlgenerator/HTMLGenerator.java index f6126a3..8427392 100644 --- a/backmeup-facebook-plugin/src/main/java/org/backmeup/facebook/htmlgenerator/HTMLGenerator.java +++ b/backmeup-facebook-plugin/src/main/java/org/backmeup/facebook/htmlgenerator/HTMLGenerator.java @@ -169,17 +169,6 @@ private void genPosts(File out, String[] postXmls) throws IOException { File picFile = FileUtils.resolveRelativePath(photoXml.getParentFile(), picProps.getProperty(PhotoInfoKey.FILE.toString())); Img pic = new Img("Photo", FileUtils.getWayTo(out, picFile)); singlePost.appendChild(pic); - - //and the picture's comments if any - /************ STARTED TESTING HERE ******************** - List commentNodes = new ArrayList<>(); - File comments = new File(postXml.getParentFile(), picProps.getProperty(PhotoInfoKey.COMMENT_DIR.toString())); - if (comments.exists()) { - for (File f : comments.listFiles()) { - commentNodes.add(genComment(f, photoHtml)); - } - } - *********** END TESTING HERE ************************/ } singlePost.setCSSClass("comment"); singlePost.appendChild(wrapInfos(PostInfoKey.values(), props, true)); diff --git a/backmeup-facebook-plugin/src/main/java/org/backmeup/facebook/storage/Serializer.java b/backmeup-facebook-plugin/src/main/java/org/backmeup/facebook/storage/Serializer.java index e7eb923..9f7f1c7 100644 --- a/backmeup-facebook-plugin/src/main/java/org/backmeup/facebook/storage/Serializer.java +++ b/backmeup-facebook-plugin/src/main/java/org/backmeup/facebook/storage/Serializer.java @@ -79,13 +79,14 @@ public static void generateAll(FacebookClient fbc, Facebook facebook, File dir, userInfo(user, true, true, new File(dir, path)); listProps.put(PropertyFile.USER.toString(), path); - // the Graph API only returns friends who are using this app, so it is - // useless to fetch them + // the Graph API only returns friends who are using this app, so it is useless to fetch them - Connection albums = fbc.fetchConnection("me/albums", Album.class, MasterParameter.getParameterByClass(Album.class)); + Connection albums = fbc.fetchConnection("me/albums", Album.class, MasterParameter.getParameterByClass(Album.class), + Parameter.with("limit", 200)); List albumList = new ArrayList<>(albums.getData()); - Connection photos = fbc.fetchConnection("me/photos", Photo.class, MasterParameter.getParameterByClass(Photo.class)); + Connection photos = fbc.fetchConnection("me/photos", Photo.class, MasterParameter.getParameterByClass(Photo.class), + Parameter.with("limit", 200)); Album lonelyAlbum = new Album(); lonelyAlbum.setName("Einzelbilder"); lonelyAlbum.setDescription("Fotos ohne Album"); @@ -105,7 +106,9 @@ public static void generateAll(FacebookClient fbc, Facebook facebook, File dir, listProps.put(PropertyFile.ALBUMS.toString(), builder.toString()); builder.empty(); - Connection posts = fbc.fetchConnection("me/posts", Post.class, MasterParameter.getParameterByClass(Post.class)); + Connection posts = fbc.fetchConnection("me/posts", Post.class, MasterParameter.getParameterByClass(Post.class), + Parameter.with("limit", 200)); + //Info: RestFB supports paging, everytime 25 elements are requested with a cursor where to receive the next ones for (Post post : posts.getData()) { path = "posts" + File.separator + post.getId() + File.separator + "postinfo.xml"; builder.append(path); @@ -219,16 +222,17 @@ public static Map postInfo(Post post, File postXml, Faceb photoInfo(photo, photoXml, fbc); infos.put(PostInfoKey.PICTURE, photoXmlPath); } catch (FacebookOAuthException e) { - LOGGER.error("Facebook sent you some bullshit", e); + LOGGER.error("error getting photo object to post with id:" + post.getObjectId(), e); } } - // In my case, it does not send any comments, but i also get no comments - // from the Graph API Explorer + // this is the proper way of requesting comments + sub-comments Connection commentConnection = fbc.fetchConnection(post.getId() + "/comments", Comment.class, - MasterParameter.getByClass(Comment.class).getParameter()); + MasterParameter.getByClass(Comment.class).getParameter(), Parameter.with("limit", 200)); for (List comments : commentConnection) { + //update the nr of received comments + infos.put(PostInfoKey.COMMENTS_COUNT, comments.size()); for (Comment comment : comments) { commentInfo(comment, new File(postXml.getParentFile(), "comments" + File.separator + comment.getId() + File.separator + "commentinfo.xml"), fbc); @@ -294,7 +298,8 @@ public static Map albumInfo(Album album, FacebookClient f if (fakeAlbum && fakePhotos != null) { photosConn = fakePhotos; } else { - photosConn = fcb.fetchConnection(album.getId() + "/photos", Photo.class, MasterParameter.getParameterByClass(Photo.class)); + photosConn = fcb.fetchConnection(album.getId() + "/photos", Photo.class, MasterParameter.getParameterByClass(Photo.class), + Parameter.with("limit", 200)); } if (progress != null) { progress.progress("Fetching " + (album.getCount() != null && (maxPics > album.getCount()) ? album.getCount() : maxPics) @@ -523,16 +528,17 @@ public static void commentInfo(Comment comment, File commentXml, FacebookClient infos.put(CommentKey.ID, comment.getId()); infos.put(CommentKey.LIKE_COUNT, comment.getLikeCount()); infos.put(CommentKey.MESSAGE, comment.getMessage()); - infos.put(CommentKey.REPLIES_COUNT, comment.getCommentCount()); + infos.put(CommentKey.REPLIES_COUNT, comment.getCommentCount()); //always zero infos.put(CommentKey.METADATA, comment.getMetadata()); writeInfos(infos, commentXml, "Represents a comment"); //check for sub-comments Connection subCommentsConnection = fbc.fetchConnection(comment.getId() + "/comments", Comment.class, - Parameter.with("limit", 10)); + Parameter.with("limit", 50)); if (subCommentsConnection != null) { for (List subcomments : subCommentsConnection) { + infos.put(CommentKey.REPLIES_COUNT, subcomments.size()); for (Comment subcomment : subcomments) { commentInfo(subcomment, new File(commentXml.getParentFile(), subcomment.getId() + "/commentinfo.xml"), fbc); } diff --git a/backmeup-facebook-plugin/src/test/java/org/backmeup/facebook/DownloadAndSerializeTester.java b/backmeup-facebook-plugin/src/test/java/org/backmeup/facebook/DownloadAndSerializeTester.java index 92ab624..893504e 100644 --- a/backmeup-facebook-plugin/src/test/java/org/backmeup/facebook/DownloadAndSerializeTester.java +++ b/backmeup-facebook-plugin/src/test/java/org/backmeup/facebook/DownloadAndSerializeTester.java @@ -40,8 +40,9 @@ public void testGenOverview() throws IOException, DatasourceException { String currentAccessToken = FacebookHelper.getProperty(FacebookHelper.RT_PROPERTY_ACCESS_TOKEN); if (currentAccessToken != null) { FacebookClient fbc = new DefaultFacebookClient(currentAccessToken, Version.VERSION_2_3); + //downlaod all information as xml Serializer.generateAll(fbc, dataDir, FacebookHelper.getDebugSkipAlbums(), FacebookHelper.getDebugMaxPics(), null); - + //create html output from xml HTMLGenerator mainGen = new HTMLGenerator(htmlDir, dataDir); mainGen.genOverview(); }