Facebook按关键字搜索

时间:2015-05-25 10:39:38

标签: r facebook facebook-graph-api

在Facebook上,我曾经使用RFacebook包中的“searchFacebook”函数搜索包含特定关键字的公共帖子,但该函数使用了新API 2中已停用的API,这是自4月30日起必须使用的API 。 我看了一下API,显然没有更多的方法以这种方式提取帖子。这是真的吗?

2 个答案:

答案 0 :(得分:1)

是的,这是事实。公共邮政搜索已经消失,没有其他选择,因此您无法再按关键字搜索。

更改日志:https://developers.facebook.com/docs/apps/changelog

编辑:它不再在更改日志中,似乎太旧了。无论哪种方式,答案仍然是正确的。

答案 1 :(得分:0)

现在,已删除使用关键字在FB上搜索公开帖子,因为他们已将Graph API更新为v2.x。

以下是我在R中获取“公共页面”的替代方法(您可以对公共组执行相同操作 - 只需将searchPage更改为searchGroup)。

所有评论/帖子/反应/回复将合并到一个单一数据集中进行分析。

searchFB <- function(key){

cat(paste("Getting data for keyword: ",key,"\n", sep = " "))


pagelist<- select(filter(searchPages(key,x, n = 10000), 
                       category == "xxxxxxxxx"),id)

cat(paste("\nTotal of relevant pages is: ",nrow(pagelist),"\n"))
# specify which date you want to start "scrapping"
begin = "xxxx"
today = Sys.Date()

# Initiate variables

page_df <- data.frame()
#post_df <- data.frame()
comment_df <- data.frame()
replies_df <- data.frame()

#pulling data for page_df and comment_df 
for (i in 1:nrow(pagelist))
{
cat("\n")
 cat(paste("Getting posts from page number ",i," with ID: ", pagelist[i,], "\n"))
target_page <- getPage(pagelist[i,],x,n=100000, since=begin , until = today,
                       feed = TRUE, reactions = TRUE)

#Adding keyword to table 
if(!empty(target_page)){
  target_page <- cbind(key, target_page)
}
page_df <- try(rbind(page_df,target_page))

#Taken from Alex's code for checking if page has no posts
for (j in 1:nrow(target_page))
{

  if(is.null(target_page$id[j])){
  } else {
    target_post <- getPost(target_page$id[j], n=100000,  x, comments = TRUE, likes = TRUE)
    #post_df<- try(rbind(post_df,target_post$post))
    comment_df <-try(rbind(comment_df,target_post$comments))
    if (class(comment_df)=="try-error")next;
  }
}
if(class(page_df)=="try-error")next;
}

cat("\n Complete collecting. Now moving to merging phase! \n")
# Join 2 data frame to create 1 consolidated dataset for each keyword

if(!empty(page_df)){
#the 2nd part of ID
for (i in 1:nrow(page_df))
{
  x<-strsplit(page_df[i,]$id,"_")[[1]]
  y<-tolower(x)[2]
  page_df$join_id[i] <-y
}}

if(!empty(comment_df)){
#the 1st part of ID
for (i in 1:nrow(comment_df))
{
  x<-strsplit(comment_df[i,]$id,"_")[[1]]
  y<-tolower(x)[1]
  comment_df$join_id[i] <-y
}}

if(empty(page_df)) {
 final_dataset<-data.frame();
} else if (empty(comment_df)){
final_dataset<-page_df
} else {
final_dataset<-full_join(page_df,comment_df,by = c("join_id"))
}


cat("\n Writing file to .csv")
write.csv(final_dataset, file = paste(key,".csv", sep = ""),
        row.names=FALSE, qmethod='escape',
        fileEncoding = "UTF-8", na = "NA")
}
# Get data for xxx 
searchFB("xxx") #type your keyword here