Skip to content
This repository has been archived by the owner on Jul 18, 2022. It is now read-only.

Commit

Permalink
make sure to provide limits when requesting the comments, posts, etc.…
Browse files Browse the repository at this point in the history
… from FB Graph API to not rely on defaults. updated broken comment count.
  • Loading branch information
andrew01ait committed Oct 14, 2015
1 parent 2fc8313 commit 7f36481
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Node> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Album> albums = fbc.fetchConnection("me/albums", Album.class, MasterParameter.getParameterByClass(Album.class));
Connection<Album> albums = fbc.fetchConnection("me/albums", Album.class, MasterParameter.getParameterByClass(Album.class),
Parameter.with("limit", 200));
List<Album> albumList = new ArrayList<>(albums.getData());

Connection<Photo> photos = fbc.fetchConnection("me/photos", Photo.class, MasterParameter.getParameterByClass(Photo.class));
Connection<Photo> 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");
Expand All @@ -105,7 +106,9 @@ public static void generateAll(FacebookClient fbc, Facebook facebook, File dir,
listProps.put(PropertyFile.ALBUMS.toString(), builder.toString());
builder.empty();

Connection<Post> posts = fbc.fetchConnection("me/posts", Post.class, MasterParameter.getParameterByClass(Post.class));
Connection<Post> 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);
Expand Down Expand Up @@ -219,16 +222,17 @@ public static Map<SerializerKey, Object> 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<Comment> commentConnection = fbc.fetchConnection(post.getId() + "/comments", Comment.class,
MasterParameter.getByClass(Comment.class).getParameter());
MasterParameter.getByClass(Comment.class).getParameter(), Parameter.with("limit", 200));

for (List<Comment> 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);
Expand Down Expand Up @@ -294,7 +298,8 @@ public static Map<SerializerKey, Object> 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)
Expand Down Expand Up @@ -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<Comment> subCommentsConnection = fbc.fetchConnection(comment.getId() + "/comments", Comment.class,
Parameter.with("limit", 10));
Parameter.with("limit", 50));
if (subCommentsConnection != null) {
for (List<Comment> subcomments : subCommentsConnection) {
infos.put(CommentKey.REPLIES_COUNT, subcomments.size());
for (Comment subcomment : subcomments) {
commentInfo(subcomment, new File(commentXml.getParentFile(), subcomment.getId() + "/commentinfo.xml"), fbc);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 7f36481

Please sign in to comment.