2017-03-10 19 views
0

我試圖訪問特定fb頁上的帖子上的所有評論getPost功能。我收到下面的錯誤。那麼我該如何解決這個問題呢?謝謝callAPI(url = url,token = token)中的錯誤:(#100)嘗試訪問節點類型(頁)上的不存在字段(from)

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) 
+0

這完全不清楚你正在運行什麼代碼。請準備一個[可重現的示例](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example),以使其更容易幫助您。 – MrFlick

回答

0

我對Rfacebook軟件包有同樣的問題。事實證明,這是因爲第一次調用(getPage)從API返回一些NA字段。因此,您的第二個電話(getPost)形成不正確。爲了防止錯誤,換你的第二個電話在這樣的if語句:

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 
    } 
} 

編輯: 另外,我覺得在你的例子你的令牌應該是「fbauthentication」,而不是「認證」。

相關問題