WhatsApp Chat Sentiment Analysis in R

Extract Youtube Comments | R Programming

Extract Youtube Comments with Youtube API


Objective: To fetch the comments of a youtube video (Baby Driver Trailer #1 (2017) | Movieclips Trailers) for further analysis




Step 1 install and load required package

>install.packages("SocialMediaLab")
>library(SocialMediaLab)

Step 2 Get access to your YouTube API Key

Log in with your google account using this Link
YouTube Data API > Credentials > Create Credentials > API 

Step 3 Authorise your API

>APIKey <- "AIzaSyDeopHDdorwQ6GIOnCi5UBDu7XKcZOIUTo" 
>Authorize <- AuthenticateWithYoutubeAPI(APIKey)

Step 4 Fetch data using video id

>VideoID <- c("D9YZw_X5UzQ")
>myutubedata<-CollectDataYoutube(videoIDs = VideoID, apiKeyYoutube = myutubeapikey, writeToFile = FALSE)

You will see following variables
Comment
User
ReplyCount
LikeCount
PublishTime
CommentID
ParentID
ReplyToAnotherUser
VideoID


Step 5 Save the comments as CSV file

>Video_Data <- as.data.frame(myutubedata)
>Video_Data <- as.data.frame(myutubedata$Comment)