0

despite reading the existing answers, I still don't know how to fix this problem.

I am trying to extract Comments For each post in the 1st phase which it is doing successfully and then in the 2nd phase for each comment extract the corresponding replies for that comment (i.e. in my program when i=1 [1st post] AND when j=1 [1st comment] )

However by the time getCommentreplies() tries to extract the very first reply for the very first comment of the first post it throws up 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

my program:

load ("fb_oauth")

fb_page_no_nullz<-getPage(page="gtbank", token=fb_oauth,n=130, since= '2018/3/10', until= '2018/3/12',feed=TRUE,api = 'v2.11')  #Extract THE LATEST n=7 FCMB posts excluding Null rows from FCMB page# into variable/vector fb_page .

no_of_rows=na.omit(nrow(fb_page_no_nullz)) #Count the number of rows without NULLS and store in var no_of_rows

i=1
all_comments<-NULL
while (i<=no_of_rows)
{

    postt <- getPost(post=fb_page_no_nullz$id[i], n=200, token=fb_oauth, comments = TRUE, likes=FALSE,  api= "v2.11" )  #Extract N comments for each post
    no_of_row_c=na.omit(nrow(postt$comments))

    if(no_of_row_c!=0) #If their are no comments for each post then pick the next post.
    {

         comment_details<-postt$comments[,1:7]
         comment_details$from_id<-comment_details$from_name<-NULL # This line removes the columns from_id AND from_name from the v data Frame

         j =1
         while (j<=no_of_row_c)

         {
             repl<-NULL
             repl<-getCommentReplies(comment_details$id[i],token=fb_oauth,n=200,replies=TRUE,likes=FALSE,n.replies=100)

             j=j+1  
         }  
    }  

    #all_comments$from_id<-all_comments$from_name<-NULL # This line removes the columns from_id AND from_name from the v data Frame
    all_comments<-rbind(all_comments,comment_details) # Cummutatively append all comments for all posts into the data frame all_comments

    i=i+1
}

#allPC<-merge(all_comments,fb_page_no_nullz, by.x= substr(c("id"),1,14), by.y=substr(c("id"),14,30),all.x = TRUE)
James Z
  • 12,209
  • 10
  • 24
  • 44

0 Answers0