我正在使用getPost
来检索帖子的评论,但无论如何都要为所有帖子提供评论吗?
提供的示例是:
getPost(post=page$id[...], token, n = 500, comments = TRUE)
其中...
是帖子的特定ID。
有没有办法检索所有帖子的评论而不必遍历帖子的每个ID?
答案 0 :(得分: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
}
答案 1 :(得分:0)
您可以尝试purrr中的map()函数:
x <- map(pag_loop$id, getPost, token = fb_oauth, n = 5000)
其中pag_loop$id
是帖子ID的向量(由getPage检索),在这种情况下,令牌是(临时)用户访问令牌。
然后:
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