library(tidyverse)
## -- Attaching packages -------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.0     v purrr   0.3.3
## v tibble  2.1.3     v dplyr   0.8.5
## v tidyr   1.0.2     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.5.0
## -- Conflicts ----------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(vosonSML)

https://www.cspoerlein.com/files/textanalyse.html

apikey <- "AIzaSyBh8VFmf7FaA6d8PIADsTi8vVrVGEbE4Xg"
key <- Authenticate("youtube", 
                    apiKey=apikey)
# You can either use this function to extract the video ID
videos <- GetYoutubeVideoIDs(c("https://www.youtube.com/watch?v=qZc5ozdiBCE"))
## Extracted 1 video ids.
# or supply it "manually": 
videos <- c("qZc5ozdiBCE")

# Either way works. If you want to download comments for multiple values, just add them to the vector of videoIDS like so: 
# videos <- c("ID1","ID2","etc")

# This will use the key and download the data
yt_data <-key %>%   
  Collect(videos)
## Collecting comment threads for youtube videos...
## Video 1 of 1
## ---------------------------------------------------------------
## ** video Id: qZc5ozdiBCE
## ** Collected threads: 446
## ** Collecting replies for 56 threads with replies. Please be patient.
## ........................................................
## ** Collected replies: 192
## ** Total video comments: 638
## ---------------------------------------------------------------
## ** Total comments collected for all videos 638.
## (Estimated API unit cost: 127)
## Done.
## Elapsed time: 0 hrs 0 mins 15 secs (15.14)
head(yt_data)
##                                                                                                                                          Comment
## 1100                                                   Mas claro, agua,  Ana Pastor y su marido Ferreras son los diablos, disfrazado, de Dioses.
## 2                                                                                 LA UE NO SIRVE PARA NADAAAA, A VER SINOS ENTERAMOS DE UNA VEZ.
## 3                                                               Viva España y viva VOX y vamos a quitar ha éste gobierno      de la presidencia.
## 4    O nos espabilamos o dentro de nada solo podremos hablar de las consignas del gobierno, no aceptan discrepancias , quiern amordazar a España
## 5                                                                  Joseph y Magda Goebbels, pero sin talento, ni belleza. O sea Ferreras y Mato.
## 6          Se empieza a inclinar la balanza ante un pueblo democráticamente consolidado. El ataque masivo y muertes inocentes caerá sobre ellos.
##                   AuthorDisplayName
## 1100                     Infanzones
## 2                           Charles
## 3           Brayan artista fenomeno
## 4                    Rosa Palomares
## 5                     Juanjo Málaga
## 6    José María Cortejoso Rodríguez
##                                                                                AuthorProfileImageUrl
## 1100 https://yt3.ggpht.com/a/AATXAJzt-gM8l9ir8L1_PSbZzLDtkrGCYNyUBEsekw=s48-c-k-c0xffffffff-no-rj-mo
## 2    https://yt3.ggpht.com/a/AATXAJzz7FJnX90gTRmtFQI4dYGg3gpP7TPfkZ2bwg=s48-c-k-c0xffffffff-no-rj-mo
## 3    https://yt3.ggpht.com/a/AATXAJwGReNmKje_Tc6g6kEBTIlZgvLprkEmKZ8k5Q=s48-c-k-c0xffffffff-no-rj-mo
## 4    https://yt3.ggpht.com/a/AATXAJzdt7WVBhhJSgrtAAXA6957lZ45wUVRqzTILQ=s48-c-k-c0xffffffff-no-rj-mo
## 5    https://yt3.ggpht.com/a/AATXAJx1Oj-q5W9OnQbJgRxajNpNPDzqfe_crfG8-Q=s48-c-k-c0xffffffff-no-rj-mo
## 6    https://yt3.ggpht.com/a/AATXAJytCEJCSkMHN2mnD1X6mQwa8iMDvhums5twxQ=s48-c-k-c0xffffffff-no-rj-mo
##                                             AuthorChannelUrl
## 1100 http://www.youtube.com/channel/UCVPRzXeHNMZvLiFe2aGM30Q
## 2    http://www.youtube.com/channel/UCDQO_EZWlRnyYQ0L5t5vHdA
## 3    http://www.youtube.com/channel/UC5nnt7QdNxOzAUrijrtSzHA
## 4    http://www.youtube.com/channel/UCPJWZjgi_z5KSI41BZEMvTA
## 5    http://www.youtube.com/channel/UCHfuF-OkRiRgUc6HlNg0miw
## 6    http://www.youtube.com/channel/UC4UvmglqZlf0N-5O7nUe5wQ
##               AuthorChannelID ReplyCount LikeCount              PublishedAt
## 1100 UCVPRzXeHNMZvLiFe2aGM30Q          0         0 2020-04-16T21:44:55.000Z
## 2    UCDQO_EZWlRnyYQ0L5t5vHdA          0         0 2020-04-16T21:44:53.000Z
## 3    UC5nnt7QdNxOzAUrijrtSzHA          0         1 2020-04-16T21:44:08.000Z
## 4    UCPJWZjgi_z5KSI41BZEMvTA          0         0 2020-04-16T21:44:07.000Z
## 5    UCHfuF-OkRiRgUc6HlNg0miw          0         0 2020-04-16T21:41:36.000Z
## 6    UC4UvmglqZlf0N-5O7nUe5wQ          0         0 2020-04-16T21:41:05.000Z
##                     UpdatedAt                  CommentID ParentID     VideoID
## 1100 2020-04-16T21:44:55.000Z UgyFZcxJqoyOaAoYvWR4AaABAg     <NA> qZc5ozdiBCE
## 2    2020-04-16T21:44:53.000Z UgyTmsUvv0bw3Fdhvxl4AaABAg     <NA> qZc5ozdiBCE
## 3    2020-04-16T21:44:08.000Z UgxcnTG08_ec23TWs0J4AaABAg     <NA> qZc5ozdiBCE
## 4    2020-04-16T21:44:07.000Z Ugyq6pyvwLU9DxHKTQt4AaABAg     <NA> qZc5ozdiBCE
## 5    2020-04-16T21:41:36.000Z Ugw8gq-1s5erqvWy9LJ4AaABAg     <NA> qZc5ozdiBCE
## 6    2020-04-16T21:41:05.000Z UgzBMnxDBoEkPxg4thp4AaABAg     <NA> qZc5ozdiBCE

Otra forma: https://github.com/soodoku/tuber USANDO tubeR

library(devtools)
## Loading required package: usethis
devtools::install_github("soodoku/tuber", build_vignettes = TRUE)
## Skipping install of 'tuber' from a github remote, the SHA1 (2cf53c50) has not changed since last install.
##   Use `force = TRUE` to force installation
library(tuber)
client_id <- "412086871179-ivmhh6p61ke87du52jco6clff9fbqpc8.apps.googleusercontent.com"
client_secret <- "6Qcf8Z0wF_-BYI-veMM-0hdo"

Esto lo pongo así porque si no no hace el knit

# use the youtube oauth 
yt_oauth(app_id = client_id,
         app_secret = client_secret,
         token = '')
#Get Statistics of a Video
stats = get_stats(video_id = "qZc5ozdiBCE")
stats
## $id
## [1] "qZc5ozdiBCE"
## 
## $viewCount
## [1] "41887"
## 
## $likeCount
## [1] "6269"
## 
## $dislikeCount
## [1] "76"
## 
## $favoriteCount
## [1] "0"
## 
## $commentCount
## [1] "623"
#Get Information About a Video
details= get_video_details(video_id = "qZc5ozdiBCE")
details
## $kind
## [1] "youtube#videoListResponse"
## 
## $etag
## [1] "\"nxOHAKTVB7baOKsQgTtJIyGxcs8/u6NVElsEiuiy7m-10cOxJ_ymoXk\""
## 
## $pageInfo
## $pageInfo$totalResults
## [1] 1
## 
## $pageInfo$resultsPerPage
## [1] 1
## 
## 
## $items
## $items[[1]]
## $items[[1]]$kind
## [1] "youtube#video"
## 
## $items[[1]]$etag
## [1] "\"nxOHAKTVB7baOKsQgTtJIyGxcs8/e3nS9CWWkbkUN7l_RYFRDcil2hM\""
## 
## $items[[1]]$id
## [1] "qZc5ozdiBCE"
## 
## $items[[1]]$snippet
## $items[[1]]$snippet$publishedAt
## [1] "2020-04-16T18:58:28.000Z"
## 
## $items[[1]]$snippet$channelId
## [1] "UCRvpumrJs0qY1xLzeU0Ss1Q"
## 
## $items[[1]]$snippet$title
## [1] "¿Qué hay detrás de Newtral y Maldita?"
## 
## $items[[1]]$snippet$description
## [1] "¿Qué hay detrás de las agencias de verificación como Newtral y Maldita? \n\nJorge Buxadé nos lo explica y anuncia nuevas acciones de VOX Europa desde el Parlamento Europeo para denunciar la censura que se pretende implantar en las redes sociales"
## 
## $items[[1]]$snippet$thumbnails
## $items[[1]]$snippet$thumbnails$default
## $items[[1]]$snippet$thumbnails$default$url
## [1] "https://i.ytimg.com/vi/qZc5ozdiBCE/default.jpg"
## 
## $items[[1]]$snippet$thumbnails$default$width
## [1] 120
## 
## $items[[1]]$snippet$thumbnails$default$height
## [1] 90
## 
## 
## $items[[1]]$snippet$thumbnails$medium
## $items[[1]]$snippet$thumbnails$medium$url
## [1] "https://i.ytimg.com/vi/qZc5ozdiBCE/mqdefault.jpg"
## 
## $items[[1]]$snippet$thumbnails$medium$width
## [1] 320
## 
## $items[[1]]$snippet$thumbnails$medium$height
## [1] 180
## 
## 
## $items[[1]]$snippet$thumbnails$high
## $items[[1]]$snippet$thumbnails$high$url
## [1] "https://i.ytimg.com/vi/qZc5ozdiBCE/hqdefault.jpg"
## 
## $items[[1]]$snippet$thumbnails$high$width
## [1] 480
## 
## $items[[1]]$snippet$thumbnails$high$height
## [1] 360
## 
## 
## $items[[1]]$snippet$thumbnails$standard
## $items[[1]]$snippet$thumbnails$standard$url
## [1] "https://i.ytimg.com/vi/qZc5ozdiBCE/sddefault.jpg"
## 
## $items[[1]]$snippet$thumbnails$standard$width
## [1] 640
## 
## $items[[1]]$snippet$thumbnails$standard$height
## [1] 480
## 
## 
## $items[[1]]$snippet$thumbnails$maxres
## $items[[1]]$snippet$thumbnails$maxres$url
## [1] "https://i.ytimg.com/vi/qZc5ozdiBCE/maxresdefault.jpg"
## 
## $items[[1]]$snippet$thumbnails$maxres$width
## [1] 1280
## 
## $items[[1]]$snippet$thumbnails$maxres$height
## [1] 720
## 
## 
## 
## $items[[1]]$snippet$channelTitle
## [1] "VOX España"
## 
## $items[[1]]$snippet$tags
## $items[[1]]$snippet$tags[[1]]
## [1] "VOX"
## 
## $items[[1]]$snippet$tags[[2]]
## [1] "VOX ESPAÑA"
## 
## $items[[1]]$snippet$tags[[3]]
## [1] "SANTIAGO ABASCAL"
## 
## $items[[1]]$snippet$tags[[4]]
## [1] "JAVIER ORTEGA SMITH"
## 
## $items[[1]]$snippet$tags[[5]]
## [1] "ESPAÑA"
## 
## 
## $items[[1]]$snippet$categoryId
## [1] "25"
## 
## $items[[1]]$snippet$liveBroadcastContent
## [1] "none"
## 
## $items[[1]]$snippet$localized
## $items[[1]]$snippet$localized$title
## [1] "¿Qué hay detrás de Newtral y Maldita?"
## 
## $items[[1]]$snippet$localized$description
## [1] "¿Qué hay detrás de las agencias de verificación como Newtral y Maldita? \n\nJorge Buxadé nos lo explica y anuncia nuevas acciones de VOX Europa desde el Parlamento Europeo para denunciar la censura que se pretende implantar en las redes sociales"
## 
## 
## $items[[1]]$snippet$defaultAudioLanguage
## [1] "es"
#Get Captions of a Video  DA ERROR
#captions = get_captions(video_id = "qZc5ozdiBCE")
#captions
#Search Videos
Vox = yt_search("Vox")
head(Vox)
##      video_id              publishedAt                channelId
## 1 o1iYSsFqVG4 2020-04-16T12:00:25.000Z UCLXo7UDZvByw2ixzpQCufnA
## 2 qZc5ozdiBCE 2020-04-16T18:58:28.000Z UCRvpumrJs0qY1xLzeU0Ss1Q
## 3 yiDZn_2_BoI 2020-04-15T12:32:56.000Z UCRvpumrJs0qY1xLzeU0Ss1Q
## 4 fUquFQGebTw 2020-04-16T10:56:27.000Z UC1IYhBFQbBWIxirTRbcfIUw
## 5 421fmflQX0E 2020-04-14T14:00:00.000Z UCLXo7UDZvByw2ixzpQCufnA
## 6 dSQztKXR6k0 2020-03-16T16:54:22.000Z UCLXo7UDZvByw2ixzpQCufnA
##                                                           title
## 1                               Why kids write letters backward
## 2                         ¿Qué hay detrás de Newtral y Maldita?
## 3              Santiago Abascal no cae en la #TrampaDeLaMoncloa
## 4 Federico Jiménez Losantos entrevista a Macarena Olona, de Vox
## 5                      What the coronavirus looks like up close
## 6                   Why fighting the coronavirus depends on you
##                                                                                                                                                          description
## 1 Almost all kids will mirror write at some point. Why? *Our in-studio shoot with other Vox team members was done before the Covid-19 outbreak. We are currently ...
## 2            Qué hay detrás de las agencias de verificación como Newtral y Maldita? Jorge Buxadé nos lo explica y anuncia nuevas acciones de VOX Europa desde el ...
## 3     El presidente de VOX rechaza la llamada con Pedro Sánchez y le pide que cese a Iglesias y pague las nóminas a los españoles a los que impide trabajar: “No ...
## 4                                                     Federico entrevista a la portavoz y secretaria general de Vox, Macarena Olona. Suscríbete a nuestro canal: ...
## 5               Seeing the virus up close helps us understand it. Support Vox by joining the Video Lab at http://vox.com/join or making a one-time contribution: ...
## 6   If we can slow the virus down, it could save hundreds of thousands of lives. Read more about the Covid-19 coronavirus pandemic at http://vox.com/coronavirus ...
##                           thumbnails.default.url thumbnails.default.width
## 1 https://i.ytimg.com/vi/o1iYSsFqVG4/default.jpg                      120
## 2 https://i.ytimg.com/vi/qZc5ozdiBCE/default.jpg                      120
## 3 https://i.ytimg.com/vi/yiDZn_2_BoI/default.jpg                      120
## 4 https://i.ytimg.com/vi/fUquFQGebTw/default.jpg                      120
## 5 https://i.ytimg.com/vi/421fmflQX0E/default.jpg                      120
## 6 https://i.ytimg.com/vi/dSQztKXR6k0/default.jpg                      120
##   thumbnails.default.height                            thumbnails.medium.url
## 1                        90 https://i.ytimg.com/vi/o1iYSsFqVG4/mqdefault.jpg
## 2                        90 https://i.ytimg.com/vi/qZc5ozdiBCE/mqdefault.jpg
## 3                        90 https://i.ytimg.com/vi/yiDZn_2_BoI/mqdefault.jpg
## 4                        90 https://i.ytimg.com/vi/fUquFQGebTw/mqdefault.jpg
## 5                        90 https://i.ytimg.com/vi/421fmflQX0E/mqdefault.jpg
## 6                        90 https://i.ytimg.com/vi/dSQztKXR6k0/mqdefault.jpg
##   thumbnails.medium.width thumbnails.medium.height
## 1                     320                      180
## 2                     320                      180
## 3                     320                      180
## 4                     320                      180
## 5                     320                      180
## 6                     320                      180
##                                thumbnails.high.url thumbnails.high.width
## 1 https://i.ytimg.com/vi/o1iYSsFqVG4/hqdefault.jpg                   480
## 2 https://i.ytimg.com/vi/qZc5ozdiBCE/hqdefault.jpg                   480
## 3 https://i.ytimg.com/vi/yiDZn_2_BoI/hqdefault.jpg                   480
## 4 https://i.ytimg.com/vi/fUquFQGebTw/hqdefault.jpg                   480
## 5 https://i.ytimg.com/vi/421fmflQX0E/hqdefault.jpg                   480
## 6 https://i.ytimg.com/vi/dSQztKXR6k0/hqdefault.jpg                   480
##   thumbnails.high.height  channelTitle liveBroadcastContent
## 1                    360           Vox                 none
## 2                    360    VOX España                 none
## 3                    360    VOX España                 none
## 4                    360 esRadiovideos                 none
## 5                    360           Vox                 none
## 6                    360           Vox                 none
#Get All the Comments Including Replies
comentarios = get_all_comments(video_id = "qZc5ozdiBCE")
head(comentarios)
##         authorDisplayName
## 1    Javier García Moreno
## 2             Iván García
## 3            Adama Diarra
## 4              Infanzones
## 5                 Charles
## 6 Brayan artista fenomeno
##                                                                             authorProfileImageUrl
## 1 https://yt3.ggpht.com/a/AATXAJx76XjFfTukRmxVc3qkiVm-zVjzCIQwMNvEeg=s48-c-k-c0xffffffff-no-rj-mo
## 2 https://yt3.ggpht.com/a/AATXAJy5tUiuZMhW7mgErgIlQhYS8VzWj67Y3Jv3ZA=s48-c-k-c0xffffffff-no-rj-mo
## 3 https://yt3.ggpht.com/a/AATXAJwUqYHqz0AVpCWq528Dg_eiwCGG5Y5V-z_sMg=s48-c-k-c0xffffffff-no-rj-mo
## 4 https://yt3.ggpht.com/a/AATXAJzt-gM8l9ir8L1_PSbZzLDtkrGCYNyUBEsekw=s48-c-k-c0xffffffff-no-rj-mo
## 5 https://yt3.ggpht.com/a/AATXAJzz7FJnX90gTRmtFQI4dYGg3gpP7TPfkZ2bwg=s48-c-k-c0xffffffff-no-rj-mo
## 6 https://yt3.ggpht.com/a/AATXAJwGReNmKje_Tc6g6kEBTIlZgvLprkEmKZ8k5Q=s48-c-k-c0xffffffff-no-rj-mo
##                                          authorChannelUrl
## 1 http://www.youtube.com/channel/UCM-N73Zj8UMtAfRakZv-EYA
## 2 http://www.youtube.com/channel/UCGbEDH9l245vwvIaeVseSAA
## 3 http://www.youtube.com/channel/UCSTKhicuS5ibXuBn-XZE6Zw
## 4 http://www.youtube.com/channel/UCVPRzXeHNMZvLiFe2aGM30Q
## 5 http://www.youtube.com/channel/UCDQO_EZWlRnyYQ0L5t5vHdA
## 6 http://www.youtube.com/channel/UC5nnt7QdNxOzAUrijrtSzHA
##      authorChannelId.value     videoId
## 1 UCM-N73Zj8UMtAfRakZv-EYA qZc5ozdiBCE
## 2 UCGbEDH9l245vwvIaeVseSAA qZc5ozdiBCE
## 3 UCSTKhicuS5ibXuBn-XZE6Zw qZc5ozdiBCE
## 4 UCVPRzXeHNMZvLiFe2aGM30Q qZc5ozdiBCE
## 5 UCDQO_EZWlRnyYQ0L5t5vHdA qZc5ozdiBCE
## 6 UC5nnt7QdNxOzAUrijrtSzHA qZc5ozdiBCE
##                                                                                                                                                                                                                            textDisplay
## 1 Sr Abascal haz algo yaaaaaa estamos esperandoooooooooo si estos siguen en el gobierno nos matan a todossssssss a que esta usted esperandoooooooooo!!!!! Sacadlos del gobierno aunque sea. Abocaossss x diosss nos van a extinguir!!!
## 2                                                                                                                                                                        Que qué hay detrás de Newtral &amp; Cía?? Comunismo y piojos.
## 3                                                                                                                                                                                                         Vox tú eres mentiroso mierda
## 4                                                                                                                                            Mas claro, agua,  Ana Pastor y su marido Ferreras son los diablos, disfrazado, de Dioses.
## 5                                                                                                                                                                       LA UE NO SIRVE PARA NADAAAA, A VER SINOS ENTERAMOS DE UNA VEZ.
## 6                                                                                                                                                     Viva España y viva VOX y vamos a quitar ha éste gobierno      de la presidencia.
##                                                                                                                                                                                                                           textOriginal
## 1 Sr Abascal haz algo yaaaaaa estamos esperandoooooooooo si estos siguen en el gobierno nos matan a todossssssss a que esta usted esperandoooooooooo!!!!! Sacadlos del gobierno aunque sea. Abocaossss x diosss nos van a extinguir!!!
## 2                                                                                                                                                                            Que qué hay detrás de Newtral & Cía?? Comunismo y piojos.
## 3                                                                                                                                                                                                         Vox tú eres mentiroso mierda
## 4                                                                                                                                            Mas claro, agua,  Ana Pastor y su marido Ferreras son los diablos, disfrazado, de Dioses.
## 5                                                                                                                                                                       LA UE NO SIRVE PARA NADAAAA, A VER SINOS ENTERAMOS DE UNA VEZ.
## 6                                                                                                                                                     Viva España y viva VOX y vamos a quitar ha éste gobierno      de la presidencia.
##   canRate viewerRating likeCount              publishedAt
## 1    TRUE         none         0 2020-04-16T21:45:26.000Z
## 2    TRUE         none         0 2020-04-16T21:45:25.000Z
## 3    TRUE         none         1 2020-04-16T21:45:21.000Z
## 4    TRUE         none         0 2020-04-16T21:44:55.000Z
## 5    TRUE         none         0 2020-04-16T21:44:53.000Z
## 6    TRUE         none         1 2020-04-16T21:44:08.000Z
##                  updatedAt                         id parentId moderationStatus
## 1 2020-04-16T21:45:26.000Z Ugw9_YxML41OSNB2ARR4AaABAg     <NA>               NA
## 2 2020-04-16T21:45:25.000Z UgyjYph9XshqozkooSN4AaABAg     <NA>               NA
## 3 2020-04-16T21:45:21.000Z UgxVZpZWgFu-RHjqQeZ4AaABAg     <NA>               NA
## 4 2020-04-16T21:44:55.000Z UgyFZcxJqoyOaAoYvWR4AaABAg     <NA>               NA
## 5 2020-04-16T21:44:53.000Z UgyTmsUvv0bw3Fdhvxl4AaABAg     <NA>               NA
## 6 2020-04-16T21:44:08.000Z UgxcnTG08_ec23TWs0J4AaABAg     <NA>               NA