Rfacebook:getpost() заменяет извлеченные данные значениями NA

Фрейм данных с данными для первых двух полей отсутствует. Функция getpost пакета Rfacebook при извлечении комментариев из facebook заменяет фактические данные для первых двух полей фрейма данных (from_id AND from_name) значением NA. Другими словами, он не извлекает идентификатор и имя автора комментария, как ожидалось.

Во-вторых, я заметил, что тип данных для этих полей во фрейме данных - ЛОГИЧЕСКИЙ, а не ХАРАКТЕР.

Почему это происходит? Какое решение решить эту проблему?

Вот мой код:


load ("fb_oauth")



#set_config(use_proxy(url="10.3.100.207",port=8080))


#library(Rfacebook)
#library(sqldf)
#library(lubridate)
#library(jsonlite)

#BEGIN: Accumulation of All Brand Posts and Comments----------------------------------------------------------------------


fb_page_no_nullz<-getPage(page="gtbank", token=fb_oauth,n=130, since= '2018/2/24', until= '2018/2/27',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

#allcomments <- data.frame(from_id=character(),from_name=character(),message=character(),created_time=character()) 

allcomments<-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_rows_c=na.omit(nrow(postt$comments))

  if (no_of_rows_c!=0) #BEGIN: If current post contains no comment Pick next post

  {


    comment_details<- postt$comments[,1:7] # Assign details of each comment to variable "comment_details"

    #BEGIN: Rename the column headers of the comments_detail data frame appropriately  
    names(comment_details)<-c("Comments_From_Id","Author_of_Comment","Comment", "Comment_Creation_Time","Comment_Likes_Count",
                              "Replies_Count","Comment_Id")
    #END: Rename the column headers of the comments_detail data frame appropriately  



    #BEGIN: For Each Comment, Include Parent Brand Post Fields eg. Brand Post, Brand Post Creation Time etc and name the columns appropriately.

    comment_details$BrandPost_Author<-c(postt$post$from_name)
    comment_details$BrandPost_From_Id<-c(postt$post$from_id)
    comment_details$BrandPost_Id<-c(postt$post$id)
    comment_details$BrandPost<-c(postt$post$message)
    comment_details$Brand_Post_Time<-c(postt$post$created_time)
    comment_details$BrandPost_Likes_Count<-c(postt$post$likes_count)
    comment_details$BrandPost_Shares_Count<-c(postt$post$shares_count)
    comment_details$BrandPost_Comments_Count<-c(postt$post$comments_count)

    #END: For Each Comment, Include Parent Brand Post Fields, eg. Brand Post, Brand Post Creation Time etc


    # postt$comments[,1:7]$Brand_Post<-c(postt$post$message)


    allcomments<-rbind(allcomments,comment_details)

  }   #END: If current post contains no comment Pick next post

  i=i+1
  #gc()
}

#END: Accumulation of All Brand Posts and Comments----------------------------------------------------------------------




allPC<-allcomments   #Accumulation of All Brand Posts and Comments stored in dataframe allPC




#BEGIN: Begin accumulation of replies for each comment and store both in data frame cr


no_of_rows_c=na.omit(nrow(allPC))

allreplies<-NULL


j=1
bount=0
cr<-NULL
#repl<-data.frame()

while (j<=no_of_rows_c)


{

 repl<-I(getCommentReplies(allPC$Comment_Id[j],token=fb_oauth,n=100,replies=TRUE,likes = FALSE, api = "v2.7")) # Extract N replies for current comment  

  print(bount)

  repc<-as.data.frame(c(repl$comment$message))
  repc$Comment_Id<-c(repl$comment$id)




  reprep$Reply_Author<-c(repl$replies$from_name)
  reprep$Reply_Time<-c(repl$replies$created_time)
  reprep$Reply_Id<-c(repl$replies$id)
  reprep$Reply_Likes_Count<-c(repl$replies$likes_count)  



  reply<-merge(repc,reprep)



  cr<-rbind(cr,reply) #Accumulate all comments and corresponding replies into the data frame cr 


  j=j+1

  #gc() 
}

#END: Begin accumulation of replies for each comment and store both in data frame cr

allCR<-cr


#BEGIN: Rename 2 fields in data frame allCR appropriately.

names(allCR)[1]<-"Comment"
names(allCR)[3]<-"Reply"

#END: Rename 2 fields in data frame allCR appropriately.


allPCR<-merge(allPC,allCR,all.x=TRUE)   #Carry out a left join on dataframes allPC AND allCR


#alllPCR<-toJSON(allPCR,pretty=TRUE) #Store Dataframe allPCR in JSON Object Variable PC


#write(alllPCR,"C:/Gboyega/1_31_Dec_2017.JSON") # Store JSON Object PCR To A Physical Data File

0 ответов

Другие вопросы по тегам