rytstat
package is an R interface for working with the
following YouTube APIs:
That is, the rytstat
allows you to request any data
available in the YouTube Creator Studio for further analysis and
visualization using the R language.
The rytstat
package for authorization uses the gargle package, the credentials
obtained during authorization are stored exclusively on your local PC,
you can find out the folder into which the credentials are cached using
the ryt_auth_cache_path()
function.
For loading data from your YouTube channel rytstat
needs
next scopes:
For more details see Official YouTube API documentation.
The package does not transfer your credentials or data obtained from your advertising accounts to third parties, however, the responsibility for information leakage remains on the side of the package user. The author does not bear any responsibility for their safety, be careful when transferring cached credentials to third parties.
For more details, I recommend that you read the following articles from the official documentation of the gargle package:
You run gads_auth('me@gmail.com')
and start OAuth
Dance in the browser:
Upon success, you see this message in the browser:
Authentication complete. Please close this page and return to R.
And you credentials cached locally on your PC in the form of RDS files.
You can use own OAuth app:
<- httr::oauth_app(appname = "app name", key = "app id", secret = "app secret")
app ryt_auth_configure(app = app)
# or from json file
ryt_auth_configure(path = 'D:/ga_auth/app.json')
# run authorization
ryt_auth('me@gmail.com')
You can install rytstat
from CRAN or GitHub:
install.packages("rytstat")
или GitHub:
::install_github('selesnow/rytstat') devtools
library(rytstat)
library(httr)
# auth app
<- oauth_app(
app appname = 'my app',
key = 'app id',
secret = 'app secret')
ryt_auth_configure(app = app)
ryt_auth(email = 'me@gmail.com')
# load channel data
<- ryt_get_channels()
channel
# load videos
<- ryt_get_video_list()
videos <- ryt_get_video_details(video_id = videos$id_video_id)
video_details
# load playlists
<- ryt_get_playlists()
pl <- ryt_get_playlist_items(
pl_items playlist_id = pl$id[1],
part = c('contentDetails', 'snippet'),
fields = 'items(id,snippet/channelId,snippet/title,contentDetails/videoId)'
)
# search channels, playlists or videos
<- ryt_search(
search_res_videos type = 'video',
q = 'r language tutorial',
published_after = '2022-03-01T00:00:00Z',
published_before = '2022-06-01T00:00:00Z',
max_results = 10
)
<- ryt_search(
search_res_playlists type = 'playlist',
q = 'r language tutorial',
published_after = '2022-03-01T00:00:00Z',
published_before = '2022-06-01T00:00:00Z',
max_results = 50
)
<- ryt_search(
search_res_channels type = 'channel',
q = 'r language tutorial',
published_after = '2022-03-01T00:00:00Z',
published_before = '2022-06-01T00:00:00Z',
max_results = 50
)
library(rytstat)
# get list of videos
<- ryt_get_video_list()
videos
# get statistics by day and videos
# you can specify no more than 500 videos at a time
<- ryt_get_analytics(
video_stat start_date = '2021-01-01',
end_date = '2021-09-01',
dimensions = c('day', 'video'),
metrics = c('views',
'likes',
'dislikes',
'comments',
'shares'),
filters = str_glue('video=={str_c(head(videos$id_video_id, 500), collapse=",")}')
)
# auth
ryt_auth('me@gmail.com')
# get reporting data
## create job
ryt_create_job('channel_basic_a2')
## get job list
<- ryt_get_job_list()
jobs2
## get job report list
<- ryt_get_report_list(
reports job_id = jobs$id[1],
created_after = '2021-10-20T15:01:23.045678Z'
)
# get report data
<- ryt_get_report(
data download_url = reports$downloadUrl[1]
)
# delete job
ryt_delete_job(jobs$id[1])
Alexey Seleznev, Head of analytics dept. at Netpeak
Telegram Channel: R4marketing
YouTube Channel: R4marketing
email: selesnow@gmail.com
facebook: facebook.com/selesnow
blog: alexeyseleznev.wordpress.com