0

I am trying to access all the comments on a post on a particular fb page using getPost function. I am getting the below error. So how can I resolve this issue? Thanks

library(Rfacebook)
load("fbauthentication")

date1<-Sys.Date()-7
date2<-Sys.Date()

MaybellineUS<-getPage(page="Maybelline",token=authentication,n=100,since=date1,until=date2,feed=TRUE)
df <- data.frame(from_id=character(),from_name=character(),message=character(),created_time=character(),
                 likes_count=numeric(),comments_count=numeric(),id=character(),stringsAsFactors = FALSE)
i <- 1
while(i<=length(MaybellineUS)){
  x<- getPost(post=MaybellineUS$id[i],n=500,token =authentication )
  df<-rbind(df,x[['comments']])
  i<-i+1
}

Error in callAPI(url = url, token = token) : 
  (#100) Tried accessing nonexisting field (from) on node type (Page)
Abhinav
  • 501
  • 1
  • 5
  • 17
  • It's totally unclear what code you are running. Please prepare a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) to make it easier to help you. – MrFlick Mar 10 '17 at 18:58

1 Answers1

0

I had the same problem with the Rfacebook package. It turns out that this is because the first call (getPage) returns some NA fields from the API. Consequently, your second call (getPost) is incorrectly formed. To prevent the error, wrap your second call in an if statement like this:

i <- 1
while(i<=length(MaybellineUS1)){
if (!is.na(MaybellineUS1$id[i]) {
x<- getPost(post=MaybellineUS1$id[i],n=500,token =authentication )
df<-rbind(df,x[['comments']])
i<-i+1
  }
}

EDIT: Also, I think in your example your token should be "fbauthentication", not "authentication".

Radim
  • 455
  • 2
  • 11