WhatsApp Chat Sentiment Analysis in R

Extract And Visualise Facebook Page Data | R Programming

Objective: To Extract the posts data of the "Deadpool Movie" Facebook page

Step 1: Install and load required package

>install.packages("Rfacebook")
>install.packages("ROAuth")
>library(Rfacebook)
>library(ROAuth) 

Step 2: Set up OAuth authentification

>my_outh<-fbOAuth(app_id = "123456789", app_secret = "520442aebfdaefcasgjahsdg76c82ad9")

Note: Put your own API ID and API Secret

Step 3: Save and load OAuth

>save(my_outh, file = "my_outh")
>load("my_outh")

Step 4: Test Your OAuth

>me<-getUsers("me", token = my_outh)
>me$name

Output: "USER NAME"

Step 5: Extract all the page's online activity

>pagedata <- getPage(709487465811929, token = my_outh, n=200)
>head(pagedata)

Step 6: Save as CSV file

>write.csv(pagedata, file = "Marvel recent posts.csv")

Output:


You will get following details:



Plot "likes_count" as histogram
>install.packages("RColourBrewer")
>library(RColourBrewer)
>hist(pagedata$likes_count, breaks = 10, col = brewer.pal(3,"Accent"))

Output: