0

I succeed getting the text of the post and share and likes count.

However, I am not able to get the like of the comments associated with the post . If this information is not avalaible , I would like to merge the like count of the post to each comments. Example: A post gets 900 likes and 80 comments. I would like to associated the 900 likes values to each of the comments (a new column called post_like maybe).

I would like to use this information to perform a sentiment analysis using the number of likes (complexe like (i.e. haha, sad...)) in a logistic regression with the frequence of the most frequent words as the x variable.

Here is my script so far:

 token<- "**ur token , get it at https://developers.facebook.com/tools/explorer/**"  

# Function to download the comments
download.post <- function(i, refetch=FALSE, path=".") {
post <- getPost(post=fb_page$id[i], comments = TRUE, likes = TRUE, token=token)
post1<- as.data.frame(melt(post)) 
}
#----------------------- Request posts  --- ALL
# Get post for ALL
fb_page<- getPage(page="**the page number u want**", token=token,  since='2010/01/01', until='2016/01/01', n= 10000, reactions=TRUE)
fb_page$order <- 1:nrow(fb_page) 

# Apply function to download comments
files<-data.frame(melt(lapply(fb_page$order, download.post)))

# Select only comments
files_c<-files[complete.cases(files$message),]

So basically I get the page with the post ID and create a function to get the post of the post ID on that page.

output for head(files_c

As you can see , I get all the information I need BESIDE the likes and share count.

I hope I am clear , thanks a lot for you help

Nico Coallier
  • 676
  • 1
  • 8
  • 22

1 Answers1

1

It's all there:

library(Rfacebook)
token <- "#############" # https://developers.facebook.com/tools/explorer 
fb_page <- getPage(page="europeanparliament", token=token, n = 3)
transform(
  fb_page[,c("message", "likes_count", "comments_count", "shares_count")], 
  message = sapply(message, toString, width=30)
)
#                          message likes_count comments_count shares_count
# 1 This week members called o....          92             73           21
# 2 Today we're all Irish, bea....         673            133           71
# 3 European citizens will mee....        1280            479           71

packageVersion("Rfacebook")
# [1] ‘0.6.12’
lukeA
  • 53,097
  • 5
  • 97
  • 100
  • thank you for your answer. I was wondering if I could get the same thing but including the comment text ? I wanna have for each post the like and the share and also a list of the comment text so I can text mine in those comment get the most frequent words and see how it match the like..I don't know if I am clear – Nico Coallier Mar 17 '17 at 17:09
  • As you can see, the function download.post ....actually download the comment on the post – Nico Coallier Mar 17 '17 at 17:10
  • 1
    I don't understand your question, because a.) my answer shows how you get the likes and shares count and b.) you know that `getPost` gives you the comments for each post. a+b is what you need, isn`t it? – lukeA Mar 17 '17 at 18:15
  • Sorry for the detail in my answer. What I want to do is to merge to like count to the comment... So lets say a post get's 900 like et 80 comments . I want each of the comment to get 900like count . – Nico Coallier Mar 21 '17 at 14:52
  • I edited the question to be more clear sorry for that ! – Nico Coallier Mar 21 '17 at 14:57