rstudiorfacebook

Issue in Facebook Replies download from post comments


I am trying to download public comments and replies from the FACEBOOK public post by page.

my code is working until 5 Feb'18, Now it is showing below error for the "Replies".

Error in data.frame(from_id = json$from$id, from_name = json$from$name,  : 
  arguments imply differing number of rows: 0, 1
Called from: data.frame(from_id = json$from$id, from_name = json$from$name, 
    message = ifelse(!is.null(json$message), json$message, NA), 
    created_time = json$created_time, likes_count = json$like_count, 
    comments_count = json$comment_count, id = json$id, stringsAsFactors = F)

please refer below code I am using.

    data_fun=function(II,JJ,page,my_oauth){
  test <- list()
  test.reply<- list()
  for (i in II:length(page$id)){
    test[[i]] <- getPost(post=page$id[i], token = my_oauth,n= 100000, comments = TRUE, likes = FALSE)
    if (nrow(test[[i]][["comments"]]) > 0) {
      write.csv(test[[i]], file = paste0(page$from_name[2],"_comments_", i, ".csv"), row.names = F)
      for (j in JJ:length(test[[i]]$comments$id)){
        test.reply[[j]] <-getCommentReplies(comment_id=test[[i]]$comments$id[j],token=my_oauth,n = 100000, replies = TRUE,likes = FALSE)
        if (nrow(test.reply[[j]][["replies"]]) > 0) {
          write.csv(test.reply[[j]], file = paste0(page$from_name[2],"_replies_",i,"_and_", j, ".csv"), row.names = F)
        }}}
}
  Sys.sleep(10)}

Thanks For Your support In advance.


Solution

  • I had the very same problem as Facebook changed the api rules at the end of January. If you update your package with 'devtools' from Pablo Barbera's github, it should work for you. I have amended my code (a little) and it works fine now for replies to comments.There is one frustrating thing though, is that Facebook dont appear to allow one to extract the user name. I have a pool of data already so I am now using that to train and predict gender. If you have any questions and want to make contact - drop me an email at 'robert.chestnutt2@mail.dcu.ie'

    By the way - it may not be an issue for you, but I have had challenges in the past writing the Rfacebook output to a csv. Saving output as an .RData file maintains the form a lot better