| Title: | Client for the YouTube API |
|---|---|
| Description: | Get comments posted on YouTube videos, information on how many times a video has been liked, search for videos with particular content, and much more. You can also scrape captions from a few videos. To learn more about the YouTube API, see <https://developers.google.com/youtube/v3/>. |
| Authors: | Gaurav Sood [aut, cre], Kate Lyons [ctb], John Muschelli [ctb] |
| Maintainer: | Gaurav Sood <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.4.0 |
| Built: | 2026-05-26 06:25:02 UTC |
| Source: | https://github.com/gojiplus/tuber |
Preserves tuber metadata attributes when subsetting
## S3 method for class 'tuber_result' x[...]## S3 method for class 'tuber_result' x[...]
x |
A tuber_result object |
... |
Arguments passed to the underlying subset method |
Add Video to Playlist
add_video_to_playlist(playlist_id, video_id, position = NULL, ...)add_video_to_playlist(playlist_id, video_id, position = NULL, ...)
playlist_id |
string; Required. The ID of the playlist. |
video_id |
string; Required. The ID of the video to add. |
position |
numeric; Optional. The position of the video in the playlist. If not provided, the video will be added to the end of the playlist. |
... |
Additional arguments passed to |
Details of the added video in the playlist.
https://developers.google.com/youtube/v3/docs/playlistItems/insert
## Not run: # Set API token via yt_oauth() first add_video_to_playlist(playlist_id = "YourPlaylistID", video_id = "2_gLD1jarfU") ## End(Not run)## Not run: # Set API token via yt_oauth() first add_video_to_playlist(playlist_id = "YourPlaylistID", video_id = "2_gLD1jarfU") ## End(Not run)
Performs a complete analysis of a YouTube channel including basic info, statistics, recent videos, and performance metrics.
analyze_channel( channel_id, max_videos = 50, auth = "key", include_comments = FALSE, ... )analyze_channel( channel_id, max_videos = 50, auth = "key", include_comments = FALSE, ... )
channel_id |
Channel ID to analyze |
max_videos |
Maximum number of recent videos to analyze (default: 50) |
auth |
Authentication method: "token" (OAuth2) or "key" (API key) |
include_comments |
Whether to fetch comment statistics (requires more quota) |
... |
Additional arguments passed to API functions |
List containing comprehensive channel analysis
## Not run: # Basic channel analysis analysis <- analyze_channel("UCuAXFkgsw1L7xaCfnd5JJOw") # Detailed analysis with comments detailed <- analyze_channel("UCuAXFkgsw1L7xaCfnd5JJOw", max_videos = 100, include_comments = TRUE) ## End(Not run)## Not run: # Basic channel analysis analysis <- analyze_channel("UCuAXFkgsw1L7xaCfnd5JJOw") # Detailed analysis with comments detailed <- analyze_channel("UCuAXFkgsw1L7xaCfnd5JJOw", max_videos = 100, include_comments = TRUE) ## End(Not run)
Analyzes trending videos and content for specific search terms or topics.
analyze_trends( search_terms, max_results = 50, time_period = "month", order = "viewCount", region_code = NULL, auth = "key", ... )analyze_trends( search_terms, max_results = 50, time_period = "month", order = "viewCount", region_code = NULL, auth = "key", ... )
search_terms |
Vector of search terms to analyze |
max_results |
Maximum results per search term (default: 50) |
time_period |
Time period for analysis: "week", "month", "year", "all" |
order |
Sort order: "relevance", "date", "rating", "viewCount" |
region_code |
Region code for localized trends |
auth |
Authentication method: "token" (OAuth2) or "key" (API key) |
... |
Additional arguments passed to search functions |
List containing trending analysis results
## Not run: # Analyze trending topics trends <- analyze_trends(c("machine learning", "AI", "data science")) # Regional trending analysis trends_us <- analyze_trends("music", region_code = "US", time_period = "week") ## End(Not run)## Not run: # Analyze trending topics trends <- analyze_trends(c("machine learning", "AI", "data science")) # Regional trending analysis trends_us <- analyze_trends("music", region_code = "US", time_period = "week") ## End(Not run)
Analyzes performance metrics for multiple videos in bulk.
bulk_video_analysis( video_ids, include_comments = FALSE, benchmark_percentiles = c(0.25, 0.5, 0.75, 0.9), auth = "key", ... )bulk_video_analysis( video_ids, include_comments = FALSE, benchmark_percentiles = c(0.25, 0.5, 0.75, 0.9), auth = "key", ... )
video_ids |
Vector of video IDs to analyze |
include_comments |
Whether to include comment analysis |
benchmark_percentiles |
Percentiles to use for performance benchmarking |
auth |
Authentication method: "token" (OAuth2) or "key" (API key) |
... |
Additional arguments passed to API functions |
List containing bulk video analysis
## Not run: # Analyze multiple videos video_ids <- c("dQw4w9WgXcQ", "M7FIvfx5J10", "kJQP7kiw5Fk") analysis <- bulk_video_analysis(video_ids) # Include comment analysis detailed <- bulk_video_analysis(video_ids, include_comments = TRUE) ## End(Not run)## Not run: # Analyze multiple videos video_ids <- c("dQw4w9WgXcQ", "M7FIvfx5J10", "kJQP7kiw5Fk") analysis <- bulk_video_analysis(video_ids) # Include comment analysis detailed <- bulk_video_analysis(video_ids, include_comments = TRUE) ## End(Not run)
This function updates the title of an existing YouTube playlist using the YouTube Data API.
change_playlist_title(playlist_id, new_title, auth = "token")change_playlist_title(playlist_id, new_title, auth = "token")
playlist_id |
A character string specifying the ID of the playlist you want to update. |
new_title |
A character string specifying the new title for the playlist. |
auth |
Authentication method: "token" (OAuth2) or "key" (API key) |
A list containing the server response after the update attempt.
## Not run: change_playlist_title(playlist_id = "YourPlaylistID", new_title = "New Playlist Title") ## End(Not run)## Not run: change_playlist_title(playlist_id = "YourPlaylistID", new_title = "New Playlist Title") ## End(Not run)
Compares statistics and performance metrics across multiple YouTube channels.
compare_channels( channel_ids, metrics = c("subscriber_count", "video_count", "view_count"), auth = "key", simplify = TRUE, ... )compare_channels( channel_ids, metrics = c("subscriber_count", "video_count", "view_count"), auth = "key", simplify = TRUE, ... )
channel_ids |
Vector of channel IDs to compare |
metrics |
Metrics to include in comparison |
auth |
Authentication method: "token" (OAuth2) or "key" (API key) |
simplify |
Whether to return a simplified comparison table |
... |
Additional arguments passed to API functions |
List or data frame with channel comparison
## Not run: # Compare two channels channels <- c("UCuAXFkgsw1L7xaCfnd5JJOw", "UCsXVk37bltHxD1rDPwtNM8Q") comparison <- compare_channels(channels) # Custom metrics comparison comparison <- compare_channels(channels, metrics = c("subscriber_count", "video_count", "view_count")) ## End(Not run)## Not run: # Compare two channels channels <- c("UCuAXFkgsw1L7xaCfnd5JJOw", "UCsXVk37bltHxD1rDPwtNM8Q") comparison <- compare_channels(channels) # Custom metrics comparison comparison <- compare_channels(channels, metrics = c("subscriber_count", "video_count", "view_count")) ## End(Not run)
Counts the number of emoji characters in text.
count_emojis(text)count_emojis(text)
text |
Character vector to count emojis in |
Integer vector with emoji counts for each element
count_emojis("Hello world") count_emojis("Hello \U0001F44B World \U0001F30D!") count_emojis(c("No emoji", "\U0001F600\U0001F601\U0001F602"))count_emojis("Hello world") count_emojis("Hello \U0001F44B World \U0001F30D!") count_emojis(c("No emoji", "\U0001F600\U0001F601\U0001F602"))
Create New Playlist
create_playlist(title, description = "", status = "public", ...)create_playlist(title, description = "", status = "public", ...)
title |
string; Required. The title of the playlist. |
description |
string; Optional. The description of the playlist. |
status |
string; Optional. Default: 'public'. Can be one of: 'private', 'public', or 'unlisted'. |
... |
Additional arguments passed to |
The created playlist's details.
https://developers.google.com/youtube/v3/docs/playlists/insert
## Not run: # Set API token via yt_oauth() first create_playlist(title = "My New Playlist", description = "This is a test playlist.") ## End(Not run)## Not run: # Set API token via yt_oauth() first create_playlist(title = "My New Playlist", description = "This is a test playlist.") ## End(Not run)
Delete a Particular Caption Track
delete_captions(id = NULL, ...)delete_captions(id = NULL, ...)
id |
String. Required. id of the caption track that is being retrieved |
... |
Additional arguments passed to |
https://developers.google.com/youtube/v3/docs/captions/delete
## Not run: # Set API token via yt_oauth() first delete_captions(id = "y3ElXcEME3lSISz6izkWVT5GvxjPu8pA") ## End(Not run)## Not run: # Set API token via yt_oauth() first delete_captions(id = "y3ElXcEME3lSISz6izkWVT5GvxjPu8pA") ## End(Not run)
Delete a Channel Section
delete_channel_sections(id = NULL, ...)delete_channel_sections(id = NULL, ...)
id |
Required. ID of the channel section. |
... |
Additional arguments passed to |
https://developers.google.com/youtube/v3/docs/channelSections/delete
## Not run: # Set API token via yt_oauth() first delete_channel_sections(c(channel_id = "UCRw8bIz2wMLmfgAgWm903cA")) ## End(Not run)## Not run: # Set API token via yt_oauth() first delete_channel_sections(c(channel_id = "UCRw8bIz2wMLmfgAgWm903cA")) ## End(Not run)
Delete a Particular Comment
delete_comments(id = NULL, ...)delete_comments(id = NULL, ...)
id |
String. Required. id of the comment being retrieved |
... |
Additional arguments passed to |
https://developers.google.com/youtube/v3/docs/comments/delete
## Not run: # Set API token via yt_oauth() first delete_comments(id = "y3ElXcEME3lSISz6izkWVT5GvxjPu8pA") ## End(Not run)## Not run: # Set API token via yt_oauth() first delete_comments(id = "y3ElXcEME3lSISz6izkWVT5GvxjPu8pA") ## End(Not run)
Delete a Playlist Item
delete_playlist_items(id = NULL, ...)delete_playlist_items(id = NULL, ...)
id |
String. Required. id of the playlist item that is to be deleted |
... |
Additional arguments passed to |
https://developers.google.com/youtube/v3/docs/playlistItems/delete
## Not run: # Set API token via yt_oauth() first delete_playlist_items(id = "YourPlaylistItemID") ## End(Not run)## Not run: # Set API token via yt_oauth() first delete_playlist_items(id = "YourPlaylistItemID") ## End(Not run)
Delete a Playlist
delete_playlists(id = NULL, ...)delete_playlists(id = NULL, ...)
id |
String. Required. id of the playlist that is to be deleted |
... |
Additional arguments passed to |
https://developers.google.com/youtube/v3/docs/playlists/delete
## Not run: # Set API token via yt_oauth() first delete_playlists(id = "y3ElXcEME3lSISz6izkWVT5GvxjPu8pA") ## End(Not run)## Not run: # Set API token via yt_oauth() first delete_playlists(id = "y3ElXcEME3lSISz6izkWVT5GvxjPu8pA") ## End(Not run)
Delete a Video
delete_videos(id = NULL, ...)delete_videos(id = NULL, ...)
id |
String. Required. id of the video that is to be deleted |
... |
Additional arguments passed to |
https://developers.google.com/youtube/v3/docs/playlistItems/delete
## Not run: # Set API token via yt_oauth() first delete_videos(id = "y3ElXcEME3lSISz6izkWVT5GvxjPu8pA") ## End(Not run)## Not run: # Set API token via yt_oauth() first delete_videos(id = "y3ElXcEME3lSISz6izkWVT5GvxjPu8pA") ## End(Not run)
Functions for YouTube API endpoints that were not previously covered in tuber, including live streaming, thumbnails, channel sections, and modern video features.
Extracts all emoji characters from text.
extract_emojis(text)extract_emojis(text)
text |
Character vector to extract emojis from |
List of character vectors, one per input element, containing extracted emojis. Returns empty character vector for elements without emojis.
extract_emojis("Hello \U0001F44B World \U0001F30D!") extract_emojis(c("No emoji", "\U0001F600 \U0001F601 \U0001F602"))extract_emojis("Hello \U0001F44B World \U0001F30D!") extract_emojis(c("No emoji", "\U0001F600 \U0001F601 \U0001F602"))
Efficiently collects all video IDs from a channel's uploads playlist, then fetches statistics and details using batch processing for optimal API quota usage.
get_all_channel_video_stats(channel_id = NULL, mine = FALSE, ...)get_all_channel_video_stats(channel_id = NULL, mine = FALSE, ...)
channel_id |
Character. Id of the channel |
mine |
Boolean. TRUE if you want to fetch stats of your own channel. Default is FALSE. |
... |
Additional arguments passed to |
A data.frame containing video metadata along with view, like,
dislike and comment counts.
If the channel_id is mistyped or there is no information, an empty list is returned
https://developers.google.com/youtube/v3/docs/channels/list
## Not run: # Set API token via yt_oauth() first get_all_channel_video_stats(channel_id="UCxOhDvtaoXDAB336AolWs3A") get_all_channel_video_stats(channel_id="UCMtFAi84ehTSYSE9Xo") # Incorrect channel ID ## End(Not run)## Not run: # Set API token via yt_oauth() first get_all_channel_video_stats(channel_id="UCxOhDvtaoXDAB336AolWs3A") get_all_channel_video_stats(channel_id="UCMtFAi84ehTSYSE9Xo") # Incorrect channel ID ## End(Not run)
Get all the comments for a video including replies
get_all_comments(video_id = NULL, max_results = NULL, ...)get_all_comments(video_id = NULL, max_results = NULL, ...)
video_id |
string; Required.
|
max_results |
Integer. Maximum number of comments to return. Default is NULL which returns all comments. Set this to avoid long-running requests on popular videos. |
... |
Additional arguments passed to |
a data.frame with the following columns:
authorDisplayName, authorProfileImageUrl, authorChannelUrl,
authorChannelId.value, videoId, textDisplay,
canRate, viewerRating, likeCount, publishedAt, updatedAt,
id, moderationStatus, parentId
https://developers.google.com/youtube/v3/docs/commentThreads/list
## Not run: # Set API token via yt_oauth() first get_all_comments(video_id = "a-UQz7fqR3w") get_all_comments(video_id = "a-UQz7fqR3w", max_results = 100) ## End(Not run)## Not run: # Set API token via yt_oauth() first get_all_comments(video_id = "a-UQz7fqR3w") get_all_comments(video_id = "a-UQz7fqR3w", max_results = 100) ## End(Not run)
Get cached response if available and valid
get_cached_response(cache_key)get_cached_response(cache_key)
cache_key |
Cache key |
Cached response or NULL if not available/expired
For getting captions from the v3 API, you must specify the id resource.
Check list_caption_tracks for more information.
IMPORTANT: This function requires OAuth authentication and you must own the video
or have appropriate permissions to access its captions.
get_captions(id = NULL, lang = "en", format = "sbv", as_raw = TRUE, ...)get_captions(id = NULL, lang = "en", format = "sbv", as_raw = TRUE, ...)
id |
String. Required. id of the caption track that is being retrieved |
lang |
Optional. Default is |
format |
Optional. Default is |
as_raw |
If |
... |
Additional arguments passed to |
String.
https://developers.google.com/youtube/v3/docs/captions/download
## Not run: # Set API token via yt_oauth() first # You must own the video to download captions get_captions(id = "y3ElXcEME3lSISz6izkWVT5GvxjPu8pA") ## End(Not run)## Not run: # Set API token via yt_oauth() first # You must own the video to download captions get_captions(id = "y3ElXcEME3lSISz6izkWVT5GvxjPu8pA") ## End(Not run)
Get channel information with caching (for static parts)
get_channel_info_cached( channel_id, part = "snippet,brandingSettings", auth = "key", cache_ttl = 3600, ... )get_channel_info_cached( channel_id, part = "snippet,brandingSettings", auth = "key", cache_ttl = 3600, ... )
channel_id |
Channel ID |
part |
Parts to retrieve (only static parts will be cached) |
auth |
Authentication method |
cache_ttl |
Cache time-to-live (default: 1 hour for channel info) |
... |
Additional arguments |
Channel information
Retrieves channel sections (featured channels, playlists, etc.).
get_channel_sections( channel_id = NULL, section_id = NULL, part = "snippet,contentDetails", simplify = TRUE, auth = "key", ... )get_channel_sections( channel_id = NULL, section_id = NULL, part = "snippet,contentDetails", simplify = TRUE, auth = "key", ... )
channel_id |
Channel ID |
section_id |
Specific section ID (optional) |
part |
Parts to retrieve |
simplify |
Whether to return a simplified data frame |
auth |
Authentication method: "token" (OAuth2) or "key" (API key) |
... |
Additional arguments passed to tuber_GET |
List or data frame with channel section information
## Not run: # Get all sections for a channel sections <- get_channel_sections(channel_id = "UCuAXFkgsw1L7xaCfnd5JJOw") # Get specific section section <- get_channel_sections(section_id = "UC_x5XG1OV2P6uZZ5FSM9Ttw.e-Fk7vMeOn4") ## End(Not run)## Not run: # Get all sections for a channel sections <- get_channel_sections(channel_id = "UCuAXFkgsw1L7xaCfnd5JJOw") # Get specific section section <- get_channel_sections(section_id = "UC_x5XG1OV2P6uZZ5FSM9Ttw.e-Fk7vMeOn4") ## End(Not run)
Get statistics and details for one or more YouTube channels efficiently using batch processing.
get_channel_stats( channel_ids = NULL, mine = NULL, part = c("statistics", "snippet"), simplify = TRUE, batch_size = 50, show_progress = NULL, auth = "token", ... ) list_my_channel(...)get_channel_stats( channel_ids = NULL, mine = NULL, part = c("statistics", "snippet"), simplify = TRUE, batch_size = 50, show_progress = NULL, auth = "token", ... ) list_my_channel(...)
channel_ids |
Character vector of channel IDs to retrieve. Use |
mine |
Logical. Set to TRUE to get authenticated user's channel.
Overrides |
part |
Character vector of parts to retrieve. Default: c("statistics", "snippet"). |
simplify |
Logical. If TRUE (default), returns a data frame. If FALSE, returns raw list. |
batch_size |
Number of channels per API call (max 50). Default: 50. |
show_progress |
Whether to show progress for large batches. Default: TRUE for >10 channels. |
auth |
Authentication method: "token" (OAuth2) or "key" (API key). Default: "token". |
... |
Additional arguments passed to |
Valid parts include: auditDetails, brandingSettings, contentDetails,
contentOwnerDetails, id, localizations, snippet, statistics, status,
topicDetails.
The function automatically batches requests to minimize API quota usage: - 1 channel = 1 API call - 100 channels = 2 API calls (batched in groups of 50)
When simplify = TRUE (default): Data frame with channel details.
When simplify = FALSE: List with channel details.
For single channels, returns the channel object directly (not in a list). For multiple channels, returns a list with items array.
https://developers.google.com/youtube/v3/docs/channels/list
## Not run: # Get stats for a single channel - displays console output stats <- get_channel_stats("UCT5Cx1l4IS3wHkJXNyuj4TA") # Get stats for multiple channels - automatically batched channel_ids <- c("UCT5Cx1l4IS3wHkJXNyuj4TA", "UCfK2eFCRQ64Gqfrpbrcj31w") stats <- get_channel_stats(channel_ids) # Get as data frame df <- get_channel_stats(channel_ids, simplify = TRUE) # Get your own channel stats my_stats <- get_channel_stats(mine = TRUE) # Get additional parts detailed <- get_channel_stats(channel_ids, part = c("statistics", "snippet", "brandingSettings")) ## End(Not run)## Not run: # Get stats for a single channel - displays console output stats <- get_channel_stats("UCT5Cx1l4IS3wHkJXNyuj4TA") # Get stats for multiple channels - automatically batched channel_ids <- c("UCT5Cx1l4IS3wHkJXNyuj4TA", "UCfK2eFCRQ64Gqfrpbrcj31w") stats <- get_channel_stats(channel_ids) # Get as data frame df <- get_channel_stats(channel_ids, simplify = TRUE) # Get your own channel stats my_stats <- get_channel_stats(mine = TRUE) # Get additional parts detailed <- get_channel_stats(channel_ids, part = c("statistics", "snippet", "brandingSettings")) ## End(Not run)
Get Comments Threads
get_comment_threads( filter = NULL, part = "snippet", text_format = "html", simplify = TRUE, max_results = 100, page_token = NULL, ... )get_comment_threads( filter = NULL, part = "snippet", text_format = "html", simplify = TRUE, max_results = 100, page_token = NULL, ... )
filter |
string; Required.
named vector of length 1
potential names of the entry in the vector:
|
part |
Comment resource requested. Required. Comma separated list
of one or more of the
following: |
text_format |
Data Type: Character. Default is |
simplify |
Data Type: Boolean. Default is |
max_results |
Maximum number of items that should be returned. Integer. Optional. Can be 1-2000. Default is 100. If the value is greater than 100, multiple API calls are made to fetch all results. Each API call is limited to 100 items per the YouTube API. |
page_token |
Specific page in the result set that should be returned. Optional. |
... |
Additional arguments passed to |
Nested named list. The entry items is a list of comments
along with meta information.
Within each of the items is an item snippet which
has an item topLevelComment$snippet$textDisplay
that contains the actual comment.
If simplify is TRUE, a data.frame with the following columns:
authorDisplayName, authorProfileImageUrl, authorChannelUrl,
authorChannelId.value, videoId, textDisplay,
canRate, viewerRating, likeCount, publishedAt, updatedAt
https://developers.google.com/youtube/v3/docs/commentThreads/list
## Not run: # Set API token via yt_oauth() first get_comment_threads(filter = c(video_id = "N708P-A45D0")) get_comment_threads(filter = c(video_id = "N708P-A45D0"), max_results = 101) ## End(Not run)## Not run: # Set API token via yt_oauth() first get_comment_threads(filter = c(video_id = "N708P-A45D0")) get_comment_threads(filter = c(video_id = "N708P-A45D0"), max_results = 101) ## End(Not run)
Get Comments
get_comments( filter = NULL, part = "snippet", max_results = 100, text_format = "html", page_token = NULL, simplify = TRUE, ... )get_comments( filter = NULL, part = "snippet", max_results = 100, text_format = "html", page_token = NULL, simplify = TRUE, ... )
filter |
string; Required.
named vector of length 1
potential names of the entry in the vector:
|
part |
Comment resource requested. Required. Comma separated list
of one or more of the
following: |
max_results |
Maximum number of items that should be returned. Integer. Optional. Can be between 20 and 100. Default is 100. |
text_format |
Data Type: Character. Default is |
page_token |
Specific page in the result set that should be returned. Optional. |
simplify |
Data Type: Boolean. Default is TRUE. If TRUE, the function returns a data frame. Else a list with all the information returned. |
... |
Additional arguments passed to |
Nested named list. The entry items is a list of comments along
with meta information.
Within each of the items is an item snippet which has an
item topLevelComment$snippet$textDisplay
that contains the actual comment.
When filter is comment_id, and simplify is TRUE,
and there is a correct comment id,
it returns a data.frame with the following cols:
id, authorDisplayName, authorProfileImageUrl, authorChannelUrl,
value, textDisplay, canRate, viewerRating, likeCount
publishedAt, updatedAt
https://developers.google.com/youtube/v3/docs/comments/list
## Not run: # Set API token via yt_oauth() first get_comments(filter = c(comment_id = "z13dh13j5rr0wbmzq04cifrhtuypwl4hsdk")) get_comments(filter = c(parent_id = "z13ds5yxjq3zzptyx04chlkbhx2yh3ezxtc0k")) get_comments(filter = c(comment_id = "z13dh13j5rr0wbmzq04cifrhtuypwl4hsdk, z13dh13j5rr0wbmzq04cifrhtuypwl4hsdk")) ## End(Not run)## Not run: # Set API token via yt_oauth() first get_comments(filter = c(comment_id = "z13dh13j5rr0wbmzq04cifrhtuypwl4hsdk")) get_comments(filter = c(parent_id = "z13ds5yxjq3zzptyx04chlkbhx2yh3ezxtc0k")) get_comments(filter = c(comment_id = "z13dh13j5rr0wbmzq04cifrhtuypwl4hsdk, z13dh13j5rr0wbmzq04cifrhtuypwl4hsdk")) ## End(Not run)
Retrieves live chat messages for a specific live chat. Note that live chat messages can only be retrieved for active live broadcasts.
get_live_chat_messages( live_chat_id, part = "snippet,authorDetails", hl = NULL, max_results = 500, page_token = NULL, profile_image_size = NULL, simplify = TRUE, ... )get_live_chat_messages( live_chat_id, part = "snippet,authorDetails", hl = NULL, max_results = 500, page_token = NULL, profile_image_size = NULL, simplify = TRUE, ... )
live_chat_id |
Character. The id of the live chat. |
part |
Character. Parts to retrieve. Valid values are "snippet", "authorDetails". Default is "snippet,authorDetails". |
hl |
Character. Language used for text values. Optional. |
max_results |
Integer. Maximum number of items to return. Default is 500. Max is 2000. |
page_token |
Character. Specific page token to retrieve. Optional. |
profile_image_size |
Integer. Size of the profile image to return. Optional. |
simplify |
Logical. Whether to return a simplified data.frame. Default is TRUE. |
... |
Additional arguments passed to |
A data.frame or list of live chat messages.
https://developers.google.com/youtube/v3/live/docs/liveChatMessages/list
## Not run: # Set API token via yt_oauth() first messages <- get_live_chat_messages(live_chat_id = "Cg0KC...") ## End(Not run)## Not run: # Set API token via yt_oauth() first messages <- get_live_chat_messages(live_chat_id = "Cg0KC...") ## End(Not run)
Retrieves information about live streams and premieres.
get_live_streams( stream_id = NULL, channel_id = NULL, part = "snippet,status", status = NULL, simplify = TRUE, auth = "token", ... )get_live_streams( stream_id = NULL, channel_id = NULL, part = "snippet,status", status = NULL, simplify = TRUE, auth = "token", ... )
stream_id |
Live stream ID (optional if using other filters) |
channel_id |
Channel ID to get live streams for |
part |
Parts to retrieve |
status |
Filter by status: "active", "upcoming", "completed" |
simplify |
Whether to return a simplified data frame |
auth |
Authentication method: "token" (OAuth2) or "key" (API key) |
... |
Additional arguments passed to tuber_GET |
List or data frame with live stream information
## Not run: # Get live streams for a channel streams <- get_live_streams(channel_id = "UCuAXFkgsw1L7xaCfnd5JJOw") # Get specific live stream details stream <- get_live_streams(stream_id = "abc123", part = c("snippet", "status")) ## End(Not run)## Not run: # Get live streams for a channel streams <- get_live_streams(channel_id = "UCuAXFkgsw1L7xaCfnd5JJOw") # Get specific live stream details stream <- get_live_streams(stream_id = "abc123", part = c("snippet", "status")) ## End(Not run)
Get Playlist Item IDs
get_playlist_item_ids( filter = NULL, part = "contentDetails", max_results = 50, video_id = NULL, page_token = NULL, simplify = TRUE, ... )get_playlist_item_ids( filter = NULL, part = "contentDetails", max_results = 50, video_id = NULL, page_token = NULL, simplify = TRUE, ... )
filter |
string; Required.
named vector of length 1
potential names of the entry in the vector:
|
part |
Required. Comma separated string including one or more of the
following: |
max_results |
Maximum number of items that should be returned. Integer. Optional. Default is 50. Values over 50 will trigger multiple requests and may increase API quota usage. |
video_id |
Optional. request should return only the playlist items that contain the specified video. |
page_token |
specific page in the result set that should be returned, optional |
simplify |
returns a data.frame rather than a list. |
... |
Additional arguments passed to |
playlist items
https://developers.google.com/youtube/v3/docs/playlists/list
## Not run: # Set API token via yt_oauth() first get_playlist_items(filter = c(playlist_id = "PLrEnWoR732-CN09YykVof2lxdI3MLOZda")) get_playlist_items(filter = c(playlist_id = "PL0fOlXVeVW9QMO3GoESky4yDgQfK2SsXN"), max_results = 51) ## End(Not run)## Not run: # Set API token via yt_oauth() first get_playlist_items(filter = c(playlist_id = "PLrEnWoR732-CN09YykVof2lxdI3MLOZda")) get_playlist_items(filter = c(playlist_id = "PL0fOlXVeVW9QMO3GoESky4yDgQfK2SsXN"), max_results = 51) ## End(Not run)
Get Playlist Item Video IDs
get_playlist_item_videoids( filter = NULL, part = "contentDetails", max_results = 50, video_id = NULL, page_token = NULL, simplify = TRUE, ... )get_playlist_item_videoids( filter = NULL, part = "contentDetails", max_results = 50, video_id = NULL, page_token = NULL, simplify = TRUE, ... )
filter |
string; Required.
named vector of length 1
potential names of the entry in the vector:
|
part |
Required. Comma separated string including one or more of the
following: |
max_results |
Maximum number of items that should be returned. Integer. Optional. Default is 50. Values over 50 trigger multiple requests and may increase API quota usage. |
video_id |
Optional. request should return only the playlist items that contain the specified video. |
page_token |
specific page in the result set that should be returned, optional |
simplify |
returns a data.frame rather than a list. |
... |
Additional arguments passed to |
playlist items
https://developers.google.com/youtube/v3/docs/playlists/list
## Not run: # Set API token via yt_oauth() first get_playlist_items(filter = c(playlist_id = "YourPlaylistID")) get_playlist_items(filter = c(playlist_id = "YourPlaylistID"), max_results = 51) ## End(Not run)## Not run: # Set API token via yt_oauth() first get_playlist_items(filter = c(playlist_id = "YourPlaylistID")) get_playlist_items(filter = c(playlist_id = "YourPlaylistID"), max_results = 51) ## End(Not run)
Get Playlist Items
get_playlist_items( filter = NULL, part = "contentDetails", max_results = 50, video_id = NULL, page_token = NULL, simplify = TRUE, ... )get_playlist_items( filter = NULL, part = "contentDetails", max_results = 50, video_id = NULL, page_token = NULL, simplify = TRUE, ... )
filter |
string; Required.
named vector of length 1
potential names of the entry in the vector:
|
part |
Required. Comma separated string including one or more of the
following: |
max_results |
Maximum number of items that should be returned. Integer. Optional. Default is 50. If over 50, additional requests are made until the requested amount is retrieved. Larger values may increase API quota usage. |
video_id |
Optional. request should return only the playlist items that contain the specified video. |
page_token |
specific page in the result set that should be returned, optional |
simplify |
returns a data.frame rather than a list. |
... |
Additional arguments passed to |
playlist items
https://developers.google.com/youtube/v3/docs/playlistItems/list
## Not run: # Set API token via yt_oauth() first get_playlist_items(filter = c(playlist_id = "PLrEnWoR732-CN09YykVof2lxdI3MLOZda")) get_playlist_items(filter = c(playlist_id = "PL0fOlXVeVW9QMO3GoESky4yDgQfK2SsXN"), max_results = 51) ## End(Not run)## Not run: # Set API token via yt_oauth() first get_playlist_items(filter = c(playlist_id = "PLrEnWoR732-CN09YykVof2lxdI3MLOZda")) get_playlist_items(filter = c(playlist_id = "PL0fOlXVeVW9QMO3GoESky4yDgQfK2SsXN"), max_results = 51) ## End(Not run)
Get Playlists
get_playlists( filter = NULL, part = "snippet", max_results = 50, hl = NULL, page_token = NULL, simplify = TRUE, ... )get_playlists( filter = NULL, part = "snippet", max_results = 50, hl = NULL, page_token = NULL, simplify = TRUE, ... )
filter |
string; Required.
named vector of length 1
potential names of the entry in the vector:
|
part |
Required. One of the following: |
max_results |
Maximum number of items that should be returned. Integer. Optional. Default is 50. Values over 50 trigger additional requests and may increase API quota usage. |
hl |
Language used for text values. Optional. Default is |
page_token |
specific page in the result set that should be returned, optional |
simplify |
Data Type: Boolean. Default is |
... |
Additional arguments passed to |
playlists
When simplify is TRUE, a data.frame with 4
columns is returned:
kind, etag, id, contentDetails.itemCount
https://developers.google.com/youtube/v3/docs/playlists/list
## Not run: # Set API token via yt_oauth() first get_playlists(filter=c(channel_id="UCMtFAi84ehTSYSE9XoHefig")) get_playlists(filter=c(channel_id="UCMtFAi84ehTSYSE9X")) # incorrect Channel ID # For searching playlists by keyword, use yt_search() instead: # yt_search(term="tutorial", channel_id="UCMtFAi84ehTSYSE9XoHefig", type="playlist") ## End(Not run)## Not run: # Set API token via yt_oauth() first get_playlists(filter=c(channel_id="UCMtFAi84ehTSYSE9XoHefig")) get_playlists(filter=c(channel_id="UCMtFAi84ehTSYSE9X")) # incorrect Channel ID # For searching playlists by keyword, use yt_search() instead: # yt_search(term="tutorial", channel_id="UCMtFAi84ehTSYSE9XoHefig", type="playlist") ## End(Not run)
Checks if videos are premieres and gets premiere scheduling information.
get_premiere_info(video_id, simplify = TRUE, auth = "key", ...)get_premiere_info(video_id, simplify = TRUE, auth = "key", ...)
video_id |
Video ID or vector of video IDs |
simplify |
Whether to return simplified data frame |
auth |
Authentication method: "token" (OAuth2) or "key" (API key) |
... |
Additional arguments passed to tuber_GET |
List or data frame with premiere information
## Not run: # Check if video is a premiere premiere_info <- get_premiere_info("dQw4w9WgXcQ") # Check multiple videos for premiere status premieres <- get_premiere_info(c("video1", "video2", "video3")) ## End(Not run)## Not run: # Check if video is a premiere premiere_info <- get_premiere_info("dQw4w9WgXcQ") # Check multiple videos for premiere status premieres <- get_premiere_info(c("video1", "video2", "video3")) ## End(Not run)
Gets view count, like count, comment count and other statistics for YouTube video(s). For unlisted videos, you must use OAuth authentication with the channel owner's credentials. Automatically uses batch processing when multiple video IDs are provided for efficiency.
get_stats( video_ids = NULL, include_content_details = FALSE, batch_size = 50, simplify = TRUE, ... )get_stats( video_ids = NULL, include_content_details = FALSE, batch_size = 50, simplify = TRUE, ... )
video_ids |
Character vector. One or more video IDs. Required. |
include_content_details |
Boolean. Include contentDetails (duration, definition, etc.) in response. Default: FALSE. |
batch_size |
Integer. Number of videos per API call when batching (max 50). Default: 50. |
simplify |
Boolean. Return simplified data frame for multiple videos. Default: TRUE. |
... |
Additional arguments passed to |
For single video: list with elements id, viewCount, likeCount,
dislikeCount, favoriteCount, commentCount. When include_content_details = TRUE,
also includes duration, definition, dimension, licensedContent, projection.
For multiple videos: data frame with one row per video (if simplify=TRUE) or list of results.
https://developers.google.com/youtube/v3/docs/videos/list#parameters
## Not run: # Set API token via yt_oauth() first # Single video get_stats(video_ids="N708P-A45D0") # Multiple videos (automatic batching) video_ids <- c("N708P-A45D0", "M7FIvfx5J10", "kJQP7kiw5Fk") stats_df <- get_stats(video_ids) # Include video duration and other content details: get_stats(video_ids="N708P-A45D0", include_content_details = TRUE) # For unlisted videos, must authenticate as channel owner: # yt_oauth("your_client_id", "your_client_secret") # get_stats(video_ids="your_unlisted_video_id") ## End(Not run)## Not run: # Set API token via yt_oauth() first # Single video get_stats(video_ids="N708P-A45D0") # Multiple videos (automatic batching) video_ids <- c("N708P-A45D0", "M7FIvfx5J10", "kJQP7kiw5Fk") stats_df <- get_stats(video_ids) # Include video duration and other content details: get_stats(video_ids="N708P-A45D0", include_content_details = TRUE) # For unlisted videos, must authenticate as channel owner: # yt_oauth("your_client_id", "your_client_secret") # get_stats(video_ids="your_unlisted_video_id") ## End(Not run)
Get Subscriptions
get_subscriptions( filter = NULL, part = "contentDetails", max_results = 50, for_channel_id = NULL, order = NULL, page_token = NULL, ... )get_subscriptions( filter = NULL, part = "contentDetails", max_results = 50, for_channel_id = NULL, order = NULL, page_token = NULL, ... )
filter |
string; Required.
named vector of length 1
potential names of the entry in the vector:
|
part |
Part of the resource requested. Required. Character.
A comma separated list of one or more of the following:
|
max_results |
Maximum number of items that should be returned. Integer. Optional. Default is 50. Values over 50 will trigger additional requests and may increase API quota usage. |
for_channel_id |
Optional. String. A comma-separated list of channel IDs. Limits response to subscriptions matching those channels. |
order |
method that will be used to sort resources in the API response. Takes one of the following: alphabetical, relevance, unread |
page_token |
Specific page in the result set that should be returned. Optional. String. |
... |
Additional arguments passed to |
named list of subscriptions
https://developers.google.com/youtube/v3/docs/subscriptions/list
## Not run: # Set API token via yt_oauth() first get_subscriptions(filter = c(channel_id = "UChTJTbr5kf3hYazJZO-euHg")) ## End(Not run)## Not run: # Set API token via yt_oauth() first get_subscriptions(filter = c(channel_id = "UChTJTbr5kf3hYazJZO-euHg")) ## End(Not run)
Retrieves Super Chat events for a channel associated with the authenticated user. This endpoint requires OAuth 2.0 authentication and the channel must be approved for Super Chat.
get_super_chat_events( part = "snippet", hl = NULL, max_results = 50, page_token = NULL, simplify = TRUE, ... )get_super_chat_events( part = "snippet", hl = NULL, max_results = 50, page_token = NULL, simplify = TRUE, ... )
part |
Parts to retrieve. Valid values are "snippet". Default is "snippet". |
hl |
Language used for text values. Optional. |
max_results |
Maximum number of items to return. Default is 50. Max is 50. |
page_token |
Specific page token to retrieve. Optional. |
simplify |
Whether to return a simplified data.frame. Default is TRUE. |
... |
Additional arguments passed to |
A data.frame or list of Super Chat events.
https://developers.google.com/youtube/v3/live/docs/superChatEvents/list
## Not run: # Set API token via yt_oauth() first super_chats <- get_super_chat_events() ## End(Not run)## Not run: # Set API token via yt_oauth() first super_chats <- get_super_chat_events() ## End(Not run)
Get details for one or more YouTube videos efficiently using batch processing.
get_video_details( video_ids, part = "snippet", simplify = TRUE, batch_size = 50, show_progress = NULL, auth = "token", ... )get_video_details( video_ids, part = "snippet", simplify = TRUE, batch_size = 50, show_progress = NULL, auth = "token", ... )
video_ids |
Character vector of video IDs to retrieve |
part |
Character vector of parts to retrieve. See |
simplify |
Logical. If TRUE, returns a data frame. If FALSE, returns raw list. Default: TRUE. |
batch_size |
Number of videos per API call (max 50). Default: 50. |
show_progress |
Whether to show progress for large batches. Default: TRUE for >10 videos. |
auth |
Authentication method: "token" (OAuth2) or "key" (API key). Default: "token". |
... |
Additional arguments passed to |
Valid values for part: contentDetails, fileDetails, id,
liveStreamingDetails, localizations, paidProductPlacementDetails, player,
processingDetails, recordingDetails, snippet, statistics, status,
suggestions, topicDetails.
Certain parts like fileDetails, suggestions, processingDetails are
only available to video owners and require OAuth authentication.
The function automatically batches requests to minimize API quota usage: - 1 video = 1 API call - 100 videos = 2 API calls (batched in groups of 50)
When simplify = TRUE (default): Data frame with video details (not available for owner-only parts).
When simplify = FALSE: List with items containing video details.
The result includes metadata as attributes:
- api_calls_made: Number of API calls made
- quota_used: Estimated quota units consumed
- videos_requested: Number of videos requested
- results_found: Number of videos found
https://developers.google.com/youtube/v3/docs/videos/list
## Not run: # Single video details <- get_video_details("yJXTXN4xrI8") # Multiple videos - automatically batched video_ids <- c("yJXTXN4xrI8", "LDZX4ooRsWs", "kJQP7kiw5Fk") details <- get_video_details(video_ids) # Get as data frame df <- get_video_details(video_ids, simplify = TRUE) # Get specific parts stats <- get_video_details(video_ids, part = c("statistics", "contentDetails")) # Extract specific fields: details <- get_video_details("yJXTXN4xrI8") title <- details$items[[1]]$snippet$title view_count <- details$items[[1]]$statistics$viewCount ## End(Not run)## Not run: # Single video details <- get_video_details("yJXTXN4xrI8") # Multiple videos - automatically batched video_ids <- c("yJXTXN4xrI8", "LDZX4ooRsWs", "kJQP7kiw5Fk") details <- get_video_details(video_ids) # Get as data frame df <- get_video_details(video_ids, simplify = TRUE) # Get specific parts stats <- get_video_details(video_ids, part = c("statistics", "contentDetails")) # Extract specific fields: details <- get_video_details("yJXTXN4xrI8") title <- details$items[[1]]$snippet$title view_count <- details$items[[1]]$statistics$viewCount ## End(Not run)
Retrieves thumbnail URLs and metadata for videos.
get_video_thumbnails(video_id, size = NULL, simplify = TRUE, auth = "key", ...)get_video_thumbnails(video_id, size = NULL, simplify = TRUE, auth = "key", ...)
video_id |
Video ID or vector of video IDs |
size |
Thumbnail size: "default", "medium", "high", "standard", "maxres" |
simplify |
Whether to return a simplified data frame |
auth |
Authentication method: "token" (OAuth2) or "key" (API key) |
... |
Additional arguments passed to tuber_GET |
List or data frame with thumbnail information
## Not run: # Get all thumbnail sizes for a video thumbs <- get_video_thumbnails("dQw4w9WgXcQ") # Get only high resolution thumbnails thumbs_hd <- get_video_thumbnails("dQw4w9WgXcQ", size = "high") # Get thumbnails for multiple videos thumbs_batch <- get_video_thumbnails(c("dQw4w9WgXcQ", "M7FIvfx5J10")) ## End(Not run)## Not run: # Get all thumbnail sizes for a video thumbs <- get_video_thumbnails("dQw4w9WgXcQ") # Get only high resolution thumbnails thumbs_hd <- get_video_thumbnails("dQw4w9WgXcQ", size = "high") # Get thumbnails for multiple videos thumbs_batch <- get_video_thumbnails(c("dQw4w9WgXcQ", "M7FIvfx5J10")) ## End(Not run)
Handle YouTube API errors with context-specific messages
handle_api_error( error_response, context_msg = "", video_id = NULL, channel_id = NULL )handle_api_error( error_response, context_msg = "", video_id = NULL, channel_id = NULL )
error_response |
The error response from the API |
context_msg |
Additional context for the error |
video_id |
Video ID if applicable for better error messages |
channel_id |
Channel ID if applicable for better error messages |
Stops execution with informative error message
Handle network/connection errors with retry suggestions
handle_network_error(error, context_msg = "")handle_network_error(error, context_msg = "")
error |
The original error |
context_msg |
Additional context for the error |
Stops execution with informative error message
Checks whether text contains any emoji characters.
has_emoji(text)has_emoji(text)
text |
Character vector to check for emojis |
Logical vector indicating whether each element contains emojis
has_emoji("Hello world") has_emoji("Hello world! \U0001F44B") has_emoji(c("No emoji", "Has emoji \U0001F600", "Also none"))has_emoji("Hello world") has_emoji("Hello world! \U0001F44B") has_emoji(c("No emoji", "Has emoji \U0001F600", "Also none"))
High-level convenience functions that combine multiple API calls to provide common YouTube analytics and research functionality out of the box.
Uploads a channel banner image to YouTube. The image must be a JPEG, PNG, or GIF. The maximum file size is 6MB. This returns a URL that you can then use with 'update_channel' (if implemented) or through the standard API to set the channel banner.
insert_channel_banner(file, channel_id = NULL, ...)insert_channel_banner(file, channel_id = NULL, ...)
file |
Character. Path to the banner image file. |
channel_id |
Character. Optional. The channel to upload the banner for (needed if using service accounts). |
... |
Additional arguments passed to |
A list containing the response from the API, including the 'url' for the banner.
https://developers.google.com/youtube/v3/docs/channelBanners/insert
## Not run: # Set API token via yt_oauth() first banner <- insert_channel_banner(file = "banner.jpg") print(banner$content$url) ## End(Not run)## Not run: # Set API token via yt_oauth() first banner <- insert_channel_banner(file = "banner.jpg") print(banner$content$url) ## End(Not run)
Check if endpoint should be cached
is_cacheable_endpoint(endpoint)is_cacheable_endpoint(endpoint)
endpoint |
API endpoint name |
Logical indicating if endpoint is cacheable
Check if query parameters indicate static data
is_static_query(endpoint, query)is_static_query(endpoint, query)
endpoint |
API endpoint |
query |
Query parameters |
Logical indicating if this specific query is cacheable
List reasons that can be used to report abusive videos
list_abuse_report_reasons(part = "id, snippet", hl = "en-US", ...)list_abuse_report_reasons(part = "id, snippet", hl = "en-US", ...)
part |
Caption resource requested. Required. Comma separated list of
one or more of the
following: |
hl |
Language used for text values. Optional. Default is |
... |
Additional arguments passed to |
If no results, empty data.frame returned
If part requested = "id, snippet" or "snippet",
data.frame with 4 columns: etag, id, label, secReasons
If part requested = "id", data.frame with 2 columns: etag, id
https://developers.google.com/youtube/v3/docs/videoAbuseReportReasons/list
## Not run: # Set API token via yt_oauth() first list_abuse_report_reasons() list_abuse_report_reasons(part="id") list_abuse_report_reasons(part="snippet") ## End(Not run)## Not run: # Set API token via yt_oauth() first list_abuse_report_reasons() list_abuse_report_reasons(part="id") list_abuse_report_reasons(part="snippet") ## End(Not run)
List Captions of a Video
list_caption_tracks( part = "snippet", video_id = NULL, lang = "en", id = NULL, simplify = TRUE, ... )list_caption_tracks( part = "snippet", video_id = NULL, lang = "en", id = NULL, simplify = TRUE, ... )
part |
Caption resource requested. Required. Comma separated
list of one or more of the
following: |
video_id |
ID of the video whose captions are requested. Required. No default. |
lang |
Language of the caption; required; default is English ("en") |
id |
comma-separated list of IDs that identify the caption resources that should be retrieved; optional; string |
simplify |
Boolean. Default is TRUE. When TRUE, and part is
|
... |
Additional arguments passed to |
list of caption tracks. When simplify is TRUE, a
data.frame is returned with
following columns: videoId, lastUpdated, trackKind, language, name,
audioTrackType, isCC,
isLarge, isEasyReader, isDraft, isAutoSynced, status, id (caption id)
https://developers.google.com/youtube/v3/docs/captions/list
## Not run: # Set API token via yt_oauth() first list_caption_tracks(video_id = "yJXTXN4xrI8") ## End(Not run)## Not run: # Set API token via yt_oauth() first list_caption_tracks(video_id = "yJXTXN4xrI8") ## End(Not run)
List Captions for YouTube Video
list_captions(video_id, query = NULL, auth = "token", ...)list_captions(video_id, query = NULL, auth = "token", ...)
video_id |
ID of the YouTube video |
query |
Fields for 'query' in 'GET' |
auth |
Authentication method: "token" (OAuth2) or "key" (API key) |
... |
Additional arguments to send to |
A list containing caption information
## Not run: video_id <- "M7FIvfx5J10" list_captions(video_id) ## End(Not run)## Not run: video_id <- "M7FIvfx5J10" list_captions(video_id) ## End(Not run)
Returns a list of channel events that match the request criteria.
list_channel_activities( filter = NULL, part = "snippet", max_results = 50, page_token = NULL, published_after = NULL, published_before = NULL, region_code = NULL, simplify = TRUE, ... )list_channel_activities( filter = NULL, part = "snippet", max_results = 50, page_token = NULL, published_after = NULL, published_before = NULL, region_code = NULL, simplify = TRUE, ... )
filter |
string; Required.
named vector of length 1
potential names of the entry in the vector:
|
part |
specify which part do you want. It can only be one of the three:
|
max_results |
Maximum number of items that should be returned. Integer. Optional. Default is 50. Values over 50 will trigger additional requests and may increase API quota usage. |
page_token |
specific page in the result set that should be returned, optional |
published_after |
Character. Optional. RFC 339 Format. For instance, "1970-01-01T00:00:00Z" |
published_before |
Character. Optional. RFC 339 Format. For instance, "1970-01-01T00:00:00Z" |
region_code |
ISO 3166-1 alpha-2 country code, optional, see also
|
simplify |
Data Type: Boolean. Default is |
... |
Additional arguments passed to |
named list
If simplify is TRUE, a data.frame is returned with 18 columns:
publishedAt, channelId, title, description, thumbnails.default.url,
thumbnails.default.width, thumbnails.default.height,
thumbnails.medium.url, thumbnails.medium.width, thumbnails.medium.height,
thumbnails.high.url, thumbnails.high.width,
thumbnails.high.height, thumbnails.standard.url, thumbnails.standard.width,
thumbnails.standard.height, channelTitle, type
https://developers.google.com/youtube/v3/docs/activities/list
## Not run: # Set API token via yt_oauth() first list_channel_activities(filter = c(channel_id = "UCRw8bIz2wMLmfgAgWm903cA")) list_channel_activities(filter = c(channel_id = "UCRw8bIz2wMLmfgAgWm903cA", regionCode="US")) list_channel_activities(filter = c(channel_id = "UCMtFAi84ehTSYSE9XoHefig"), published_before = "2016-02-10T00:00:00Z", published_after = "2016-01-01T00:00:00Z") ## End(Not run)## Not run: # Set API token via yt_oauth() first list_channel_activities(filter = c(channel_id = "UCRw8bIz2wMLmfgAgWm903cA")) list_channel_activities(filter = c(channel_id = "UCRw8bIz2wMLmfgAgWm903cA", regionCode="US")) list_channel_activities(filter = c(channel_id = "UCMtFAi84ehTSYSE9XoHefig"), published_before = "2016-02-10T00:00:00Z", published_after = "2016-01-01T00:00:00Z") ## End(Not run)
Retrieves a list of members for a channel associated with the authenticated user. This endpoint requires OAuth 2.0 authentication and the channel must have memberships enabled.
list_channel_members( part = "snippet", max_results = 50, page_token = NULL, mode = "all_current", has_access_to_level = NULL, simplify = TRUE, ... )list_channel_members( part = "snippet", max_results = 50, page_token = NULL, mode = "all_current", has_access_to_level = NULL, simplify = TRUE, ... )
part |
Parts to retrieve. Valid values are "snippet". Default is "snippet". |
max_results |
Maximum number of items to return. Default is 50. Max is 1000. |
page_token |
Specific page token to retrieve. Optional. |
mode |
Filter for members. Valid values: "all_current", "newest". Default is "all_current". |
has_access_to_level |
Filter by a specific membership level ID. Optional. |
simplify |
Whether to return a simplified data.frame. Default is TRUE. |
... |
Additional arguments passed to |
A data.frame or list of channel members.
https://developers.google.com/youtube/v3/docs/members/list
## Not run: # Set API token via yt_oauth() first members <- list_channel_members() ## End(Not run)## Not run: # Set API token via yt_oauth() first members <- list_channel_members() ## End(Not run)
Returns List of Requested Channel Resources
list_channel_resources( filter = NULL, part = "contentDetails", max_results = 50, page_token = NULL, hl = "en-US", simplify = TRUE, ... )list_channel_resources( filter = NULL, part = "contentDetails", max_results = 50, page_token = NULL, hl = "en-US", simplify = TRUE, ... )
filter |
string; Required.
named vector with a single valid name
potential names of the entry in the vector:
|
part |
a comma-separated list of channel resource properties that
response will include a string. Required.
One of the following: |
max_results |
Maximum number of items that should be returned. Integer. Optional. Default is 50. Values over 50 will trigger additional requests and may increase API quota usage. |
page_token |
specific page in the result set that should be returned, optional |
hl |
Language used for text values. Optional. The default is |
simplify |
Logical. If TRUE, returns a data frame. If FALSE, returns raw list. Default: TRUE. |
... |
Additional arguments passed to |
If simplify = TRUE (default) or username is used in filter,
a data frame. Otherwise returns a list.
https://developers.google.com/youtube/v3/docs/channels/list
## Not run: # Set API token via yt_oauth() first list_channel_resources(filter = c(channel_id = "UCT5Cx1l4IS3wHkJXNyuj4TA")) list_channel_resources(filter = c(username = "latenight"), part = "id") list_channel_resources(filter = c(username = c("latenight", "PBS")), part = "id") ## End(Not run)## Not run: # Set API token via yt_oauth() first list_channel_resources(filter = c(channel_id = "UCT5Cx1l4IS3wHkJXNyuj4TA")) list_channel_resources(filter = c(username = "latenight"), part = "id") list_channel_resources(filter = c(username = c("latenight", "PBS")), part = "id") ## End(Not run)
Returns list of channel sections that channel id belongs to.
list_channel_sections(filter = NULL, part = "snippet", hl = NULL, ...)list_channel_sections(filter = NULL, part = "snippet", hl = NULL, ...)
filter |
string; Required.
named vector of length 1
potential names of the entry in the vector:
|
part |
specify which part do you want. It can only be one of the
following: |
hl |
language that will be used for text values, optional, default
is en-US. See also |
... |
Additional arguments passed to |
captions for the video from one of the first track
https://developers.google.com/youtube/v3/docs/activities/list
## Not run: # Set API token via yt_oauth() first list_channel_sections(c(channel_id = "UCRw8bIz2wMLmfgAgWm903cA")) ## End(Not run)## Not run: # Set API token via yt_oauth() first list_channel_sections(c(channel_id = "UCRw8bIz2wMLmfgAgWm903cA")) ## End(Not run)
Iterate through the max_results number of playlists in channel and get
the videos for each of the playlists.
list_channel_videos( channel_id = NULL, max_results = 50, page_token = NULL, hl = "en-US", ... )list_channel_videos( channel_id = NULL, max_results = 50, page_token = NULL, hl = "en-US", ... )
channel_id |
String. ID of the channel. Required. |
max_results |
Maximum number of videos returned. Integer. Default is 50. If the number is over 50, all the videos will be returned. |
page_token |
Specific page in the result set that should be returned. Optional. |
hl |
Language used for text values. Optional. Default is |
... |
Additional arguments passed to |
list of data.frame with each list corresponding to a different
playlist
https://developers.google.com/youtube/v3/docs/channels/list
## Not run: # Set API token via yt_oauth() first list_channel_videos(channel_id = "UCXOKEdfOFxsHO_-Su3K8SHg") list_channel_videos(channel_id = "UCXOKEdfOFxsHO_-Su3K8SHg", max_results = 10) ## End(Not run)## Not run: # Set API token via yt_oauth() first list_channel_videos(channel_id = "UCXOKEdfOFxsHO_-Su3K8SHg") list_channel_videos(channel_id = "UCXOKEdfOFxsHO_-Su3K8SHg", max_results = 10) ## End(Not run)
Get list of categories that can be associated with YouTube channels
list_guidecats(filter = NULL, hl = NULL, ...)list_guidecats(filter = NULL, hl = NULL, ...)
filter |
string; Required.
named vector of length 1
potential names of the entry in the vector:
|
hl |
Language used for text values. Optional. Default is |
... |
Additional arguments passed to |
data.frame with 5 columns: region_code, channelId, title,
etag, id
https://developers.google.com/youtube/v3/docs/guideCategories/list
## Not run: # Set API token via yt_oauth() first list_guidecats(c(region_code = "JP")) ## End(Not run)## Not run: # Set API token via yt_oauth() first list_guidecats(c(region_code = "JP")) ## End(Not run)
List Languages That YouTube Currently Supports
list_langs(hl = NULL, ...)list_langs(hl = NULL, ...)
hl |
Language used for text values. Optional. Default is |
... |
Additional arguments passed to |
data.frame with 3 columns: hl (two letter abbreviation),
name (of the language), etag
https://developers.google.com/youtube/v3/docs/i18nLanguages/list
## Not run: # Set API token via yt_oauth() first list_langs() ## End(Not run)## Not run: # Set API token via yt_oauth() first list_langs() ## End(Not run)
List supported languages with caching
list_langs_cached(auth = "key", cache_ttl = 86400, ...)list_langs_cached(auth = "key", cache_ttl = 86400, ...)
auth |
Authentication method |
cache_ttl |
Cache time-to-live (default: 24 hours) |
... |
Additional arguments |
Languages data
List My videos
list_my_videos(...)list_my_videos(...)
... |
additional arguments to pass to |
data.frame with each list corresponding to a different
playlist
## Not run: list_my_videos() ## End(Not run)## Not run: list_my_videos() ## End(Not run)
List Content Regions That YouTube Currently Supports
list_regions(hl = NULL, ...)list_regions(hl = NULL, ...)
hl |
Language used for text values. Optional. Default is |
... |
Additional arguments passed to |
data.frame with 3 columns:
gl (two letter abbreviation), name (of the region), etag
https://developers.google.com/youtube/v3/docs/i18nRegions/list
## Not run: # Set API token via yt_oauth() first list_regions() ## End(Not run)## Not run: # Set API token via yt_oauth() first list_regions() ## End(Not run)
List supported regions with caching
list_regions_cached(auth = "key", cache_ttl = 86400, ...)list_regions_cached(auth = "key", cache_ttl = 86400, ...)
auth |
Authentication method |
cache_ttl |
Cache time-to-live (default: 24 hours) |
... |
Additional arguments |
Regions data
List of Categories That Can be Associated with Videos
list_videocats(filter = NULL, ...)list_videocats(filter = NULL, ...)
filter |
string; Required.
named vector of length 1
potential names of the entry in the vector:
|
... |
Additional arguments passed to |
data.frame with 6 columns: region_code, channelId, title, assignable, etag, id
https://developers.google.com/youtube/v3/docs/videoCategories/list
## Not run: # Set API token via yt_oauth() first list_videocats(c(region_code = "JP")) list_videocats() # Will throw an error asking for a valid filter with valid region_code ## End(Not run)## Not run: # Set API token via yt_oauth() first list_videocats(c(region_code = "JP")) list_videocats() # Will throw an error asking for a valid filter with valid region_code ## End(Not run)
These functions automatically cache responses to reduce API quota usage for data that changes infrequently. List video categories with caching
list_videocats_cached(region_code = "US", auth = "key", cache_ttl = 86400, ...)list_videocats_cached(region_code = "US", auth = "key", cache_ttl = 86400, ...)
region_code |
Region code for categories |
auth |
Authentication method |
cache_ttl |
Cache time-to-live (default: 24 hours for categories) |
... |
Additional arguments |
Video categories data
List (Most Popular) Videos
list_videos( part = "contentDetails", max_results = 50, page_token = NULL, hl = NULL, region_code = NULL, video_category_id = NULL, ... )list_videos( part = "contentDetails", max_results = 50, page_token = NULL, hl = NULL, region_code = NULL, video_category_id = NULL, ... )
part |
Required. Comma separated string including one or more of the
following: |
max_results |
Maximum number of items that should be returned. Integer. Optional. Default is 50. Values over 50 will trigger multiple requests and may use additional API quota. |
page_token |
specific page in the result set that should be returned, optional |
hl |
Language used for text values. Optional. Default is |
region_code |
Character. Required. Has to be a ISO 3166-1 alpha-2 code (see https://www.iso.org/obp/ui/#search). |
video_category_id |
the video category for which the chart should be
retrieved. See also |
... |
Additional arguments passed to |
data.frame with 5 columns: channelId, title, assignable, etag, id
https://developers.google.com/youtube/v3/docs/search/list
## Not run: # Set API token via yt_oauth() first list_videos() ## End(Not run)## Not run: # Set API token via yt_oauth() first list_videos() ## End(Not run)
Posts a new top-level comment on a YouTube video or channel. Requires OAuth 2.0 authentication.
post_comment(video_id = NULL, channel_id = NULL, text, ...)post_comment(video_id = NULL, channel_id = NULL, text, ...)
video_id |
Character. ID of the video to comment on. Either 'video_id' or 'channel_id' must be provided. |
channel_id |
Character. ID of the channel to comment on. |
text |
Character. The text of the comment. |
... |
Additional arguments passed to |
A list containing the API response.
https://developers.google.com/youtube/v3/docs/commentThreads/insert
## Not run: # Set API token via yt_oauth() first post_comment(video_id = "yJXTXN4xrI8", text = "Great video!") ## End(Not run)## Not run: # Set API token via yt_oauth() first post_comment(video_id = "yJXTXN4xrI8", text = "Great video!") ## End(Not run)
Custom print method that shows key metadata alongside the result data
## S3 method for class 'tuber_result' print(x, ...)## S3 method for class 'tuber_result' print(x, ...)
x |
A tuber_result object |
... |
Additional arguments passed to default print methods |
Read SBV file
read_sbv(file)read_sbv(file)
file |
The file name of the |
A data.frame with start/stop times and the text
if (yt_authorized()) { vids <- list_my_videos() res <- list_caption_tracks(video_id = vids$contentDetails.videoId[1]) cap <- get_captions(id = res$id, as_raw = FALSE) tfile <- tempfile(fileext = ".sbv") writeLines(cap, tfile) x <- read_sbv(tfile) if (requireNamespace("hms", quietly = TRUE)) { x$start <- hms::as_hms(x$start) x$stop <- hms::as_hms(x$stop) } }if (yt_authorized()) { vids <- list_my_videos() res <- list_caption_tracks(video_id = vids$contentDetails.videoId[1]) cap <- get_captions(id = res$id, as_raw = FALSE) tfile <- tempfile(fileext = ".sbv") writeLines(cap, tfile) x <- read_sbv(tfile) if (requireNamespace("hms", quietly = TRUE)) { x$start <- hms::as_hms(x$start) x$stop <- hms::as_hms(x$stop) } }
Removes all emoji characters from text.
remove_emojis(text)remove_emojis(text)
text |
Character vector to remove emojis from |
Character vector with emojis removed
remove_emojis("Hello \U0001F44B World!") remove_emojis(c("No emoji", "Has \U0001F600 emoji"))remove_emojis("Hello \U0001F44B World!") remove_emojis(c("No emoji", "Has \U0001F600 emoji"))
Replaces all emoji characters with a specified string.
replace_emojis(text, replacement = "")replace_emojis(text, replacement = "")
text |
Character vector to process |
replacement |
String to replace emojis with. Default: "" (empty string) |
Character vector with emojis replaced
replace_emojis("Hello \U0001F44B World!", replacement = "[emoji]") replace_emojis("Rate: \U0001F600\U0001F600\U0001F600", replacement = "*")replace_emojis("Hello \U0001F44B World!", replacement = "[emoji]") replace_emojis("Rate: \U0001F600\U0001F600\U0001F600", replacement = "*")
Replies to an existing comment. Requires OAuth 2.0 authentication.
reply_to_comment(parent_id, text, ...)reply_to_comment(parent_id, text, ...)
parent_id |
Character. The ID of the comment being replied to. |
text |
Character. The text of the reply. |
... |
Additional arguments passed to |
A list containing the API response.
https://developers.google.com/youtube/v3/docs/comments/insert
## Not run: # Set API token via yt_oauth() first reply_to_comment(parent_id = "Ugz...", text = "Thanks for watching!") ## End(Not run)## Not run: # Set API token via yt_oauth() first reply_to_comment(parent_id = "Ugz...", text = "Thanks for watching!") ## End(Not run)
Search specifically for YouTube Shorts videos.
search_shorts( query, max_results = 25, order = "relevance", region_code = NULL, published_after = NULL, published_before = NULL, simplify = TRUE, auth = "key", ... )search_shorts( query, max_results = 25, order = "relevance", region_code = NULL, published_after = NULL, published_before = NULL, simplify = TRUE, auth = "key", ... )
query |
Search query |
max_results |
Maximum number of results (1-50) |
order |
Sort order: "date", "rating", "relevance", "title", "viewCount" |
region_code |
Region code for search |
published_after |
RFC 3339 formatted date-time (e.g., "2023-01-01T00:00:00Z") |
published_before |
RFC 3339 formatted date-time |
simplify |
Whether to return simplified data frame |
auth |
Authentication method: "token" (OAuth2) or "key" (API key) |
... |
Additional arguments passed to tuber_GET |
List or data frame with search results for shorts
## Not run: # Search for recent shorts about cats shorts <- search_shorts("cats", max_results = 25, order = "date") # Search for popular shorts in a specific region shorts_us <- search_shorts("music", region_code = "US", order = "viewCount") ## End(Not run)## Not run: # Search for recent shorts about cats shorts <- search_shorts("cats", max_results = 25, order = "date") # Search for popular shorts in a specific region shorts_us <- search_shorts("music", region_code = "US", order = "viewCount") ## End(Not run)
Sets the moderation status of one or more comments. Requires OAuth 2.0 authentication and owner privileges.
set_comment_moderation_status( comment_id, moderation_status, ban_author = FALSE, ... )set_comment_moderation_status( comment_id, moderation_status, ban_author = FALSE, ... )
comment_id |
Character vector. The IDs of the comments to update. |
moderation_status |
Character. Valid values are 'heldForReview', 'published', 'rejected'. |
ban_author |
Logical. Whether to ban the author from commenting on the channel. Optional. |
... |
Additional arguments passed to |
A list containing the API response.
https://developers.google.com/youtube/v3/docs/comments/setModerationStatus
## Not run: # Set API token via yt_oauth() first set_comment_moderation_status(comment_id = "Ugz...", moderation_status = "rejected") ## End(Not run)## Not run: # Set API token via yt_oauth() first set_comment_moderation_status(comment_id = "Ugz...", moderation_status = "rejected") ## End(Not run)
Uploads a custom video thumbnail to YouTube and sets it for a video. Requires OAuth 2.0 authentication.
set_video_thumbnail(video_id, file, ...)set_video_thumbnail(video_id, file, ...)
video_id |
Character. ID of the video to set the thumbnail for. |
file |
Character. Path to the thumbnail image file (JPG or PNG, max 2MB). |
... |
Additional arguments passed to |
A list containing the response from the API.
https://developers.google.com/youtube/v3/docs/thumbnails/set
## Not run: # Set API token via yt_oauth() first set_video_thumbnail(video_id = "yJXTXN4xrI8", file = "thumbnail.jpg") ## End(Not run)## Not run: # Set API token via yt_oauth() first set_video_thumbnail(video_id = "yJXTXN4xrI8", file = "thumbnail.jpg") ## End(Not run)
Store response in cache
store_cached_response(cache_key, data, ttl = NULL)store_cached_response(cache_key, data, ttl = NULL)
cache_key |
Cache key |
data |
Response data to cache |
ttl |
Time-to-live in seconds (NULL for default) |
Provide helpful suggestions for common user errors
suggest_solution(issue_type, details = "")suggest_solution(issue_type, details = "")
issue_type |
Type of issue encountered |
details |
Additional details for the suggestion |
Displays a summary of the tuber API result including metadata
## S3 method for class 'tuber_result' summary(object, ...)## S3 method for class 'tuber_result' summary(object, ...)
object |
A tuber_result object |
... |
Additional arguments (ignored) |
tuber provides access to the YouTube API V3 via RESTful calls.
Clear cache entries
tuber_cache_clear(pattern = NULL, older_than = NULL)tuber_cache_clear(pattern = NULL, older_than = NULL)
pattern |
Regular expression pattern to match cache keys (NULL for all) |
older_than |
Clear entries older than this many seconds |
Configure caching settings
tuber_cache_config( enabled = TRUE, default_ttl = 3600, max_size = 1000, cache_dir = NULL )tuber_cache_config( enabled = TRUE, default_ttl = 3600, max_size = 1000, cache_dir = NULL )
enabled |
Whether to enable caching globally |
default_ttl |
Default time-to-live in seconds |
max_size |
Maximum number of cached items |
cache_dir |
Directory for persistent cache (NULL for memory only) |
Get current cache configuration
tuber_cache_info()tuber_cache_info()
List with cache configuration
Request Response Verification
tuber_check(req)tuber_check(req)
req |
request |
in case of failure, a message
DELETE
tuber_DELETE(path, query, auth = "token", ...)tuber_DELETE(path, query, auth = "token", ...)
path |
path to specific API request URL |
query |
query list |
auth |
A character vector of the authentication method, either "token" (the default) or "key" |
... |
Additional arguments passed to |
list
GET
tuber_GET(path, query, auth = "token", use_etag = TRUE, ...)tuber_GET(path, query, auth = "token", use_etag = TRUE, ...)
path |
path to specific API request URL |
query |
query list |
auth |
A character vector of the authentication method, either "token" (the default) or "key" |
use_etag |
Logical. Whether to use ETag for caching. Default is TRUE. |
... |
Additional arguments passed to |
list
Cached version of tuber_GET with automatic caching
tuber_GET_cached( path, query, auth = "token", cache_ttl = NULL, force_refresh = FALSE, ... )tuber_GET_cached( path, query, auth = "token", cache_ttl = NULL, force_refresh = FALSE, ... )
path |
API endpoint path |
query |
Query parameters |
auth |
Authentication method |
cache_ttl |
Override default TTL for this call |
force_refresh |
Skip cache and force fresh API call |
... |
Additional arguments passed to tuber_GET |
API response (from cache or fresh call)
Shows the metadata attributes added to tuber function results for debugging and quota management.
tuber_info(result)tuber_info(result)
result |
A result object from a tuber function with metadata attributes |
## Not run: result <- get_video_details("dQw4w9WgXcQ") tuber_info(result) ## End(Not run)## Not run: result <- get_video_details("dQw4w9WgXcQ") tuber_info(result) ## End(Not run)
POST
tuber_POST(path, query, body = "", auth = "token", ...)tuber_POST(path, query, body = "", auth = "token", ...)
path |
path to specific API request URL |
query |
query list |
body |
passing image through body |
auth |
A character vector of the authentication method, either "token" (the default) or "key" |
... |
Additional arguments passed to |
list
POST encoded in json
tuber_POST_json(path, query, body = "", ...)tuber_POST_json(path, query, body = "", ...)
path |
path to specific API request URL |
query |
query list |
body |
passing image through body |
... |
Additional arguments passed to |
list
PUT
tuber_PUT(path, query, body = "", auth = "token", ...)tuber_PUT(path, query, body = "", auth = "token", ...)
path |
path to specific API request URL |
query |
query list |
body |
JSON body content for the PUT request |
auth |
A character vector of the authentication method, either "token" (the default) or "key" |
... |
Additional arguments passed to |
list
Functions for consistent text and Unicode handling across tuber, including emoji detection, extraction, and manipulation.
This function updates the metadata of an existing YouTube video using the YouTube Data API.
update_video_metadata( video_id, title, category_id, description, privacy_status, made_for_kids, auth = "token" )update_video_metadata( video_id, title, category_id, description, privacy_status, made_for_kids, auth = "token" )
video_id |
A character string specifying the ID of the video you want to update. |
title |
A character string specifying the new title for the video. |
category_id |
A character string specifying the new category ID for the video. |
description |
A character string specifying the new description for the video. |
privacy_status |
A character string specifying the new privacy status for the video ('public', 'private', or 'unlisted'). |
made_for_kids |
A boolean specifying whether the video is self-declared as made for kids. |
auth |
Authentication method: "token" (OAuth2) or "key" (API key) |
A list containing the server response after the update attempt.
## Not run: update_video_metadata(video_id = "YourVideoID", title = "New Video Title", category_id = "24", description = "New Description", privacy_status = "public", made_for_kids = FALSE) ## End(Not run)## Not run: update_video_metadata(video_id = "YourVideoID", title = "New Video Title", category_id = "24", description = "New Description", privacy_status = "public", made_for_kids = FALSE) ## End(Not run)
Upload Video Caption to Youtube
upload_caption( file, video_id, language = "en-US", caption_name, is_draft = FALSE, query = NULL, open_url = FALSE, ... )upload_caption( file, video_id, language = "en-US", caption_name, is_draft = FALSE, query = NULL, open_url = FALSE, ... )
file |
Filename of the caption file with timing information (e.g., '.srt', '.vtt'). As of April 12, 2024, timing information is required for all caption uploads. |
video_id |
YouTube Video ID. Try |
language |
character string of 'BCP47' language type. See https://www.rfc-editor.org/rfc/bcp/bcp47.txt for language specification |
caption_name |
character vector of the name for the caption. |
is_draft |
logical indicating whether the caption track is a draft. |
query |
Fields for 'query' in 'POST' |
open_url |
Should the video be opened using |
... |
Additional arguments to send to |
A list of the response object from the POST, content,
and the URL of the video
See https://developers.google.com/youtube/v3/docs/captions#resource for full specification
## Not run: xx = list_my_videos() video_id = xx$contentDetails.videoId[1] video_id = as.character(video_id) language = "en-US" ## End(Not run)## Not run: xx = list_my_videos() video_id = xx$contentDetails.videoId[1] video_id = as.character(video_id) language = "en-US" ## End(Not run)
Upload Video to Youtube
upload_video( file, snippet = NULL, status = list(privacyStatus = "public"), query = NULL, open_url = FALSE, ... )upload_video( file, snippet = NULL, status = list(privacyStatus = "public"), query = NULL, open_url = FALSE, ... )
file |
Filename of the video locally |
snippet |
Additional fields for the video, including 'description' and 'title'. See https://developers.google.com/youtube/v3/docs/videos#resource for other fields. Coerced to a JSON object |
status |
Additional fields to be put into the |
query |
Fields for 'query' in 'POST' |
open_url |
Should the video be opened using |
... |
Additional arguments to send to |
A list of the response object from the POST, content,
and the URL of the uploaded
The information for 'status' and 'snippet' are at https://developers.google.com/youtube/v3/docs/videos#resource but the subset of these fields to pass in are located at: https://developers.google.com/youtube/v3/docs/videos/insert The 'part“ parameter serves two purposes in this operation. It identifies the properties that the write operation will set, this will be automatically detected by the names of 'body'. See https://developers.google.com/youtube/v3/docs/videos/insert#usage
## Not run: snippet = list( title = "Test Video", description = "This is just a random test.", tags = c("r language", "r programming", "data analysis") ) status = list(privacyStatus = "private") ## End(Not run)## Not run: snippet = list( title = "Test Video", description = "This is just a random test.", tags = c("r language", "r programming", "data analysis") ) status = list(privacyStatus = "private") ## End(Not run)
Validate YouTube channel ID format
validate_channel_id(channel_id, name = "channel_id")validate_channel_id(channel_id, name = "channel_id")
channel_id |
Channel ID to validate |
name |
Parameter name for error messages |
Invisible NULL if valid, stops execution if invalid
Validate language codes
validate_language_code(language_code, name = "language_code")validate_language_code(language_code, name = "language_code")
language_code |
Language code to validate (ISO 639-1 or BCP-47) |
name |
Parameter name for error messages |
Invisible NULL if valid, stops execution if invalid
Validate YouTube API part parameters
validate_part_parameter(part, endpoint, name = "part")validate_part_parameter(part, endpoint, name = "part")
part |
Part parameter value(s) |
endpoint |
API endpoint name for context-specific validation |
name |
Parameter name for error messages |
Invisible NULL if valid, stops execution if invalid
Validate YouTube playlist ID format
validate_playlist_id(playlist_id, name = "playlist_id")validate_playlist_id(playlist_id, name = "playlist_id")
playlist_id |
Playlist ID to validate |
name |
Parameter name for error messages |
Invisible NULL if valid, stops execution if invalid
Validate region codes
validate_region_code(region_code, name = "region_code")validate_region_code(region_code, name = "region_code")
region_code |
Region code to validate (ISO 3166-1 alpha-2) |
name |
Parameter name for error messages |
Invisible NULL if valid, stops execution if invalid
Validate RFC 3339 date format for YouTube API
validate_rfc3339_date(date_string, name)validate_rfc3339_date(date_string, name)
date_string |
Date string to validate |
name |
Parameter name for error messages |
Invisible NULL if valid, stops execution if invalid
Validate YouTube video ID format
validate_video_id(video_id, name = "video_id")validate_video_id(video_id, name = "video_id")
video_id |
Video ID to validate |
name |
Parameter name for error messages |
Invisible NULL if valid, stops execution if invalid
Warn about deprecated functionality with migration guidance
warn_deprecated(old_function, new_function, version = "next major version")warn_deprecated(old_function, new_function, version = "next major version")
old_function |
Name of deprecated function |
new_function |
Name of replacement function |
version |
Version when deprecation will become an error |
Implements exponential backoff with jitter for retrying failed API calls
with_retry( expr, max_retries = 3, base_delay = 1, max_delay = 60, backoff_factor = 2, jitter = TRUE, retry_on = function(e) is_transient_error(e), on_retry = NULL )with_retry( expr, max_retries = 3, base_delay = 1, max_delay = 60, backoff_factor = 2, jitter = TRUE, retry_on = function(e) is_transient_error(e), on_retry = NULL )
expr |
Expression to evaluate (usually an API call) |
max_retries |
Maximum number of retry attempts |
base_delay |
Base delay in seconds for first retry |
max_delay |
Maximum delay in seconds |
backoff_factor |
Multiplier for delay between retries |
jitter |
Whether to add random jitter to prevent thundering herd |
retry_on |
Function that takes an error and returns TRUE if should retry |
on_retry |
Function called on each retry attempt with attempt number and error |
Result of successful expression evaluation
Returns the current estimated quota usage for the day
yt_get_quota_usage()yt_get_quota_usage()
List with quota_used, quota_limit, quota_remaining, and reset_time
## Not run: quota_status <- yt_get_quota_usage() cat("Used:", quota_status$quota_used, "/", quota_status$quota_limit) ## End(Not run)## Not run: quota_status <- yt_get_quota_usage() cat("Used:", quota_status$quota_used, "/", quota_status$quota_limit) ## End(Not run)
These functions manage your YouTube API key and package key in .Renviron.
yt_get_key(decrypt = FALSE) yt_set_key(key, type)yt_get_key(decrypt = FALSE) yt_set_key(key, type)
decrypt |
A boolean vector specifying whether to decrypt the supplied key with 'httr2::secret_decrypt()'. Defaults to 'FALSE'. If 'TRUE', requires the environment variable 'TUBER_KEY' to be set in '.Renviron'. |
key |
A character vector specifying a YouTube API key. |
type |
A character vector specifying the type of API key to set. One of 'api' (the default, stored in ‘YOUTUBE_KEY') or ’package'. Package keys are stored in 'TUBER_KEY' and are used to decrypt API keys, for use in continuous integration and testing. |
'yt_get_key()' returns a character vector with the YouTube API key stored in '.Renviron'. If this value is not stored in '.Renviron', the functions return 'NULL'.
When the ‘type' argument is set to ’api', ‘yt_set_key()' assigns a YouTube API key to 'YOUTUBE_KEY' in '.Renviron' and invisibly returns 'NULL'. When the 'type' argument is set to ’package', 'yt_set_key()' assigns a package key to 'TUBER_KEY' in '.Renviron' and invisibly returns 'NULL'.
## Not run: ## for interactive use yt_get_key() list_channel_videos( channel_id = "UCDgj5-mFohWZ5irWSFMFcng", max_results = 3, part = "snippet", auth = "key" ) ## for continuous integration and testing yt_set_key(httr2::secret_make_key(), type = "package") x <- httr2::secret_encrypt("YOUR_YOUTUBE_API_KEY", "TUBER_KEY") yt_set_key(x, type = "api") yt_get_key(decrypt = TRUE) list_channel_videos( channel_id = "UCDgj5-mFohWZ5irWSFMFcng", max_results = 3, part = "snippet", auth = "key" ) ## End(Not run)## Not run: ## for interactive use yt_get_key() list_channel_videos( channel_id = "UCDgj5-mFohWZ5irWSFMFcng", max_results = 3, part = "snippet", auth = "key" ) ## for continuous integration and testing yt_set_key(httr2::secret_make_key(), type = "package") x <- httr2::secret_encrypt("YOUR_YOUTUBE_API_KEY", "TUBER_KEY") yt_set_key(x, type = "api") yt_get_key(decrypt = TRUE) list_channel_videos( channel_id = "UCDgj5-mFohWZ5irWSFMFcng", max_results = 3, part = "snippet", auth = "key" ) ## End(Not run)
The function looks for .httr-oauth in the working directory. If it
doesn't find it, it expects an application ID and a secret.
If you want to remove the existing .httr-oauth, set remove_old_oauth
to TRUE. By default, it is set to FALSE.
The function launches a browser to allow you to authorize the application
yt_oauth( app_id = NULL, app_secret = NULL, scope = "ssl", token = ".httr-oauth", ... )yt_oauth( app_id = NULL, app_secret = NULL, scope = "ssl", token = ".httr-oauth", ... )
app_id |
client id; required; no default |
app_secret |
client secret; required; no default |
scope |
Character. |
token |
path to file containing the token. If a path is given,
the function will first try to read from it.
Default is |
... |
Additional arguments passed to |
If a browser cannot be opened, pass use_oob = TRUE to
yt_oauth() so authentication can be completed using an
out-of-band code.
Delete the .httr-oauth file in the working directory to force
re-authentication.
sets the google_token option and also saves .httr_oauth
in the working directory (find out the working directory via getwd())
https://developers.google.com/youtube/v3/docs/
https://developers.google.com/youtube/v3/guides/auth/client-side-web-apps for different scopes
## Not run: yt_oauth(paste0("998136489867-5t3tq1g7hbovoj46dreqd6k5kd35ctjn", ".apps.googleusercontent.com"), "MbOSt6cQhhFkwETXKur-L9rN") ## End(Not run)## Not run: yt_oauth(paste0("998136489867-5t3tq1g7hbovoj46dreqd6k5kd35ctjn", ".apps.googleusercontent.com"), "MbOSt6cQhhFkwETXKur-L9rN") ## End(Not run)
Reset the quota counter (typically done automatically at midnight UTC)
yt_reset_quota()yt_reset_quota()
Search for videos, channels and playlists. (By default, the function searches for videos.)
yt_search( term = NULL, max_results = 50, channel_id = NULL, channel_type = NULL, type = "video", event_type = NULL, location = NULL, location_radius = NULL, published_after = NULL, published_before = NULL, video_definition = "any", video_caption = "any", video_license = "any", video_syndicated = "any", region_code = NULL, relevance_language = "en", video_type = "any", simplify = TRUE, get_all = TRUE, page_token = NULL, max_pages = Inf, ... )yt_search( term = NULL, max_results = 50, channel_id = NULL, channel_type = NULL, type = "video", event_type = NULL, location = NULL, location_radius = NULL, published_after = NULL, published_before = NULL, video_definition = "any", video_caption = "any", video_license = "any", video_syndicated = "any", region_code = NULL, relevance_language = "en", video_type = "any", simplify = TRUE, get_all = TRUE, page_token = NULL, max_pages = Inf, ... )
term |
Character. Search term; required; no default For using Boolean operators, see the API documentation. Here's some of the relevant information: "Your request can also use the Boolean NOT (-) and OR (|) operators to exclude videos or to find videos that are associated with one of several search terms. For example, to search for videos matching either "boating" or "sailing", set the q parameter value to boating|sailing. Similarly, to search for videos matching either "boating" or "sailing" but not "fishing", set the q parameter value to boating|sailing -fishing" |
max_results |
Maximum number of items that should be returned in total.
Integer. Optional. Can be between 1 and 500. Default is 50. If
|
channel_id |
Character. Only return search results from this channel; Optional. |
channel_type |
Character. Optional. Takes one of two values:
|
type |
Character. Optional. Takes one of three values:
|
event_type |
Character. Optional. Takes one of three values:
|
location |
Character. Optional. Latitude and Longitude within parentheses, e.g. "(37.42307,-122.08427)" |
location_radius |
Character. Optional. e.g. "1500m", "5km", "10000ft", "0.75mi" |
published_after |
Character. Optional. RFC 339 Format. For instance, "1970-01-01T00:00:00Z" |
published_before |
Character. Optional. RFC 339 Format. For instance, "1970-01-01T00:00:00Z" |
video_definition |
Character. Optional.
Takes one of three values: |
video_caption |
Character. Optional. Takes one of three values:
|
video_license |
Character. Optional.
Takes one of three values: |
video_syndicated |
Character. Optional. Takes one of two values:
|
region_code |
Character. Required. Has to be a ISO 3166-1 alpha-2 code (see https://www.iso.org/obp/ui/#search). |
relevance_language |
Character. Optional. The relevance_language argument instructs the API to return search results that are most relevant to the specified language. The parameter value is typically an ISO 639-1 two-letter language code. However, you should use the values zh-Hans for simplified Chinese and zh-Hant for traditional Chinese. Please note that results in other languages will still be returned if they are highly relevant to the search query term. |
video_type |
Character. Optional. Takes one of three values:
|
simplify |
Boolean. Return a data.frame if |
get_all |
get all results, iterating through all the results
pages. Default is |
page_token |
specific page in the result set that should be returned, optional |
max_pages |
Maximum number of pages to retrieve when get_all is TRUE. Default is Inf (no page limit). Setting a lower value can reduce API quota usage. |
... |
Additional arguments passed to |
data.frame with 16 elements: video_id, publishedAt,
channelId, title, description,
thumbnails.default.url, thumbnails.default.width, thumbnails.default.height,
thumbnails.medium.url,
thumbnails.medium.width, thumbnails.medium.height, thumbnails.high.url,
thumbnails.high.width,
thumbnails.high.height, channelTitle, liveBroadcastContent
The returned data.frame also has the following attributes:
total_results: The total number of results reported by the API
actual_results: The actual number of rows returned
api_limit_reached: Whether the YouTube API result limit was reached
https://developers.google.com/youtube/v3/docs/search/list
## Not run: # Set API token via yt_oauth() first yt_search(term = "Barack Obama") yt_search(term = "Barack Obama", published_after = "2016-10-01T00:00:00Z") yt_search(term = "Barack Obama", published_before = "2016-09-01T00:00:00Z") yt_search(term = "Barack Obama", published_before = "2016-03-01T00:00:00Z", published_after = "2016-02-01T00:00:00Z") yt_search(term = "Barack Obama", published_before = "2016-02-10T00:00:00Z", published_after = "2016-01-01T00:00:00Z") # To check how many results were found vs. how many were returned: results <- yt_search(term = "drone videos") attr(results, "total_results") # Total number reported by YouTube attr(results, "actual_results") # Number actually returned attr(results, "api_limit_reached") # Whether API limit was reached ## End(Not run)## Not run: # Set API token via yt_oauth() first yt_search(term = "Barack Obama") yt_search(term = "Barack Obama", published_after = "2016-10-01T00:00:00Z") yt_search(term = "Barack Obama", published_before = "2016-09-01T00:00:00Z") yt_search(term = "Barack Obama", published_before = "2016-03-01T00:00:00Z", published_after = "2016-02-01T00:00:00Z") yt_search(term = "Barack Obama", published_before = "2016-02-10T00:00:00Z", published_after = "2016-01-01T00:00:00Z") # To check how many results were found vs. how many were returned: results <- yt_search(term = "drone videos") attr(results, "total_results") # Total number reported by YouTube attr(results, "actual_results") # Number actually returned attr(results, "api_limit_reached") # Whether API limit was reached ## End(Not run)
Set the daily quota limit (default is 10,000 units)
yt_set_quota_limit(limit)yt_set_quota_limit(limit)
limit |
Integer. Daily quota limit in units |
## Not run: # If you have a higher quota limit yt_set_quota_limit(50000) ## End(Not run)## Not run: # If you have a higher quota limit yt_set_quota_limit(50000) ## End(Not run)
Check if authentication token is in options
yt_token() yt_authorized() yt_check_token()yt_token() yt_authorized() yt_check_token()
A Token2.0 class
Search YouTube by Topic It uses the Freebase list of topics
yt_topic_search(topic = NULL, ...)yt_topic_search(topic = NULL, ...)
topic |
topic being searched for; required; no default |
... |
Additional arguments passed to |
a list
## Not run: # Set API token via yt_oauth() first yt_topic_search(topic = "Barack Obama") ## End(Not run)## Not run: # Set API token via yt_oauth() first yt_topic_search(topic = "Barack Obama") ## End(Not run)