2017-04-21 75 views
0

我正在使用getPost檢索帖子的評論,但無論如何這樣做的所有職位?檢索Rfacebook中的多個帖子的評論

提供的例子是:

getPost(post=page$id[...], token, n = 500, comments = TRUE) 

其中...是郵政的特定ID。

有沒有什麼辦法可以檢索所有帖子的評論,而無需遍歷帖子的每個ID?

回答

0

你可以從purrr嘗試map()函數:

x <- map(pag_loop$id, getPost, token = fb_oauth, n = 5000) 

其中pag_loop$id是(通過GETPAGE檢索)職位ID的向量,這種情況下的令牌是(臨時)用戶訪問令牌。

然後:

df_info_total <- do.call(rbind, x) #large matrix de 3*number_of_posts elementos 
df_info_total <- bind_rows(df_info_total) #to get the total dataframe 
0

Rfacebook包中沒有檢索帖子評論的直接函數。你將不得不迭代所有的帖子ID並且刪除他們的評論來獲得所有的評論。你將不得不做這樣的事情:

i<-1 
    df<-data.frame(from_id=numeric(),message=character(),....,id=numeric(),stringsAsFactors = FALSE) 
    while(i<=nrow(posts)){ 
     comments<-getPost(post=posts$id[i],token=fb_oauth,n=500)[['comments']] 
     df<-rbind(df,comments) 
     i<-i+1 
    }