Scraping Comment replies with Rfacebook

1k views Asked by At

I am using the Rfacebook package to scrape a List of public pages that are of interest for my research question. The authentification works properly and I can get dataframes of all public posts, reactions towards the posts and comments made on these posts.

However, I´m running into an issue when I try to extract the replies to comments under the public posts. This is the code that I´m using:

BSBKB <-getPage("bersenbrueckerkreisblatt", token = my_OAuth, feed = TRUE, reactions = TRUE,verbose = TRUE, n = 1000)
#Getting comments for Post No.4
Comments <- getPost(BSBKB$id[4],token = my_OAuth, reactions = TRUE, n =180,likes=TRUE)
#Getting replies to comment No.4 under Post No.4
replies <- getCommentReplies(Comments$comments$id[4], token = my_OAuth, n = 500, replies = FALSE, likes= TRUE)

This code throws the following Error:

Error in data.frame(from_id = json$from$id, from_name = json$from$name,  : arguments imply differing number of rows: 0, 1

Strangely enough, the same Error occurs when I try to run the example code from the ?getCommentReplies() page:

## Not run: 
## See examples for fbOAuth to know how token was created.
## Getting information about Facebook's Facebook Page
   load("fb_oauth")
   fb_page <- getPage(page="facebook", token=my_OAuth)
## Getting information and likes/comments about most recent post
   post <- getPost(post=fb_page$id[1], n=2000, token=my_OAuth)
## Downloading list of replies to first comment
   replies <- getCommentReplies(comment_id=post$comments$id[1], token=my_OAuth) 
## End(Not run)

Resulting in:

Error in data.frame(from_id = json$from$id, from_name = json$from$name,  : 
  arguments imply differing number of rows: 0, 1

Is this a systematic error in the package, a recent change in the API or did I make a mistake somewhere? Any suggestions on how to work around this and to extract comment replies (and reactions to them ideally) would be great!

1

There are 1 answers

3
Albert Hupa On

The sourcecode of the function getCommentReplies is published on Github: https://github.com/yanturgeon/R_Script/blob/master/getCommentReplies_dev.R

Reload this code in your own environment, but before you do it, commentout the line:

out[["reply"]] <- replyDataToDF(content)

The effect will be still list, not a dataframe.