WhatsApp Chat Sentiment Analysis in R

Extract Comments From Facebook Posts

Objective: To extract comments of a public post of BMW's FB page.

Step 1: Install and load required packages


Step 2: Authorise OAuth usinf APP ID, APP Secret and Access Token

#Generate APP Token and Access Token click Here

>my_outh <- fbOAuth(app_id = "YOUR APP ID", app_secret = "YOUR APP SECRET")
>acess_token <-"YOUR ACCESS TOKEN"

Step 3: Save and Load OAuth

>save(my_outh,file = "my_outh")

Step 4: Extract page data

>pagedata<-getPage(22893372268,token = acess_token,n=10)

## Getting information and likes/comments about most recent post
>post <- getPost(post=pagedata$id[4], token=acess_token)
>post$comments[3] ##See comments

## transform it into a dataframe and save the comments as CSV file
>df<-data.frame(words = unlist(post)) 
>write.csv(df, file = "BMWcomments.csv")