Title: | An Interface to the YouTube API |
---|---|
Description: | Manage YouTube videos from R. |
Authors: | Kevin Kent [aut, cre], Jon Harmon [aut] |
Maintainer: | Kevin Kent <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.0.9001 |
Built: | 2024-11-18 14:25:16 UTC |
Source: | https://github.com/kevin-m-kent/youtubeR |
Launch the Google Cloud "Credentials" page (where you can configure OAuth 2.0
Clients). After you configure a client, copy/paste the Client ID and Client
Secret into the YOUTUBE_CLIENT_ID
and YOUTUBE_CLIENT_SECRET
environment
variables. We recommend placing these environment variables in your
.Renviron
file.
browse_gc_credentials()
browse_gc_credentials()
The url of the "Credentials" page, invisibly.
gc_credentials_url <- browse_gc_credentials() # Copy/paste values from your client. Sys.setenv(YOUTUBE_CLIENT_ID = "12345-ab12c.apps.googleusercontent.com") Sys.setenv(YOUTUBE_CLIENT_SECRET = "ABCD-eFg_H")
gc_credentials_url <- browse_gc_credentials() # Copy/paste values from your client. Sys.setenv(YOUTUBE_CLIENT_ID = "12345-ab12c.apps.googleusercontent.com") Sys.setenv(YOUTUBE_CLIENT_SECRET = "ABCD-eFg_H")
Create an object of type "POSIXct". This function is used to provide a length-0 placeholder value in function definitions.
datetime()
datetime()
A length-0 POSIXct object.
datetime()
datetime()
Get ids of playlists that contain details about the content of a channel.
get_my_channel_detail_playlist_ids( client = yt_construct_client(), cache_disk = getOption("yt_cache_disk", FALSE), cache_key = getOption("yt_cache_key", NULL), token = NULL )
get_my_channel_detail_playlist_ids( client = yt_construct_client(), cache_disk = getOption("yt_cache_disk", FALSE), cache_key = getOption("yt_cache_key", NULL), token = NULL )
client |
A YouTube OAuth client created with |
cache_disk |
Should the access token be cached on disk? This reduces the number of times that you need to re-authenticate at the cost of storing access credentials on disk. Learn more in https://httr2.r-lib.org/articles/oauth.html. |
cache_key |
If you are authenticating with multiple users using the same client, use this key to differentiate between those users. |
token |
A YouTube API OAuth token, or the |
The contentDetails object encapsulates information about the channel's content.
Property | Class | Description |
watchHistory | character | The ID of the playlist that contains the channel's watch history. Use the playlistItems.insert and playlistItems.delete to add or remove items from that list. |
likes | character | The ID of the playlist that contains the channel's liked videos. Use the playlistItems.insert and playlistItems.delete to add or remove items from that list. |
favorites | character | The ID of the playlist that contains the channel's favorite videos. Use the playlistItems.insert and playlistItems.delete to add or remove items from that list. |
watchLater | character | The ID of the playlist that contains the channel's watch later playlist. Use the playlistItems.insert and playlistItems.delete to add or remove items from that list. |
uploads | character | The ID of the playlist that contains the channel's uploaded videos. Use the videos.insert method to upload new videos and the videos.delete method to delete previously uploaded videos. |
get_my_channel_details()
get_my_channel_details()
Retrieve a list of items in a given playlist.
get_playlist_items( playlist_id, max_results = 100, client = yt_construct_client(), cache_disk = getOption("youtuberR.cache_disk", FALSE), cache_key = getOption("youtuberR.cache_key", NULL), token = NULL )
get_playlist_items( playlist_id, max_results = 100, client = yt_construct_client(), cache_disk = getOption("youtuberR.cache_disk", FALSE), cache_key = getOption("youtuberR.cache_key", NULL), token = NULL )
playlist_id |
The ID of a playlist. |
max_results |
The maximum number of results to return. |
client |
A YouTube OAuth client created with |
cache_disk |
Should the access token be cached on disk? This reduces the number of times that you need to re-authenticate at the cost of storing access credentials on disk. Learn more in https://httr2.r-lib.org/articles/oauth.html. |
cache_key |
If you are authenticating with multiple users using the same client, use this key to differentiate between those users. |
token |
A YouTube API OAuth token, or the |
A list of videos, each of which has a videoId and a videoPublishedAt.
get_playlist_items(playlist_id = get_upload_playlist_id())
get_playlist_items(playlist_id = get_upload_playlist_id())
Retrieves video ids for a particular playlist.
get_playlist_video_ids( playlist_id, max_results = 100, client = yt_construct_client(), cache_disk = getOption("yt_cache_disk", FALSE), cache_key = getOption("yt_cache_key", NULL), token = NULL )
get_playlist_video_ids( playlist_id, max_results = 100, client = yt_construct_client(), cache_disk = getOption("yt_cache_disk", FALSE), cache_key = getOption("yt_cache_key", NULL), token = NULL )
playlist_id |
The ID of a playlist. |
max_results |
The maximum number of results to return. |
client |
A YouTube OAuth client created with |
cache_disk |
Should the access token be cached on disk? This reduces the number of times that you need to re-authenticate at the cost of storing access credentials on disk. Learn more in https://httr2.r-lib.org/articles/oauth.html. |
cache_key |
If you are authenticating with multiple users using the same client, use this key to differentiate between those users. |
token |
A YouTube API OAuth token, or the |
A character vector of video ids.
get_playlist_video_ids(playlist_id = get_upload_playlist_id())
get_playlist_video_ids(playlist_id = get_upload_playlist_id())
Retrieves the upload playlist ids.
get_upload_playlist_id( client = yt_construct_client(), cache_disk = getOption("yt_cache_disk", FALSE), cache_key = getOption("yt_cache_key", NULL), token = NULL )
get_upload_playlist_id( client = yt_construct_client(), cache_disk = getOption("yt_cache_disk", FALSE), cache_key = getOption("yt_cache_key", NULL), token = NULL )
client |
A YouTube OAuth client created with |
cache_disk |
Should the access token be cached on disk? This reduces the number of times that you need to re-authenticate at the cost of storing access credentials on disk. Learn more in https://httr2.r-lib.org/articles/oauth.html. |
cache_key |
If you are authenticating with multiple users using the same client, use this key to differentiate between those users. |
token |
A YouTube API OAuth token, or the |
list of playlist ids for uploads
get_upload_playlist_id()
get_upload_playlist_id()
Retrieves the processing details for a vector of video IDs
get_video_processing_details( video_ids, client = yt_construct_client(), cache_disk = getOption("yt_cache_disk", FALSE), cache_key = getOption("yt_cache_key", NULL), token = NULL )
get_video_processing_details( video_ids, client = yt_construct_client(), cache_disk = getOption("yt_cache_disk", FALSE), cache_key = getOption("yt_cache_key", NULL), token = NULL )
video_ids |
A character vector of video ids. |
client |
A YouTube OAuth client created with |
cache_disk |
Should the access token be cached on disk? This reduces the number of times that you need to re-authenticate at the cost of storing access credentials on disk. Learn more in https://httr2.r-lib.org/articles/oauth.html. |
cache_key |
If you are authenticating with multiple users using the same client, use this key to differentiate between those users. |
token |
A YouTube API OAuth token, or the |
A list of processing status details. processingStatus is probably of most interest
get_upload_playlist_id() |> get_playlist_items() |> get_video_processing_details()
get_upload_playlist_id() |> get_playlist_items() |> get_video_processing_details()
Load or generate a YouTube OAuth token for use in the other functions in this package. The primary use of this function is to cache values early in a script (so the user can walk away). Otherwise the other functions in this package will prompt for authentication when needed. Once the values are cached, the rest of this package will use them by default for that client.
yt_authenticate( client = yt_construct_client(), force = FALSE, refresh_token = NULL )
yt_authenticate( client = yt_construct_client(), force = FALSE, refresh_token = NULL )
client |
A YouTube OAuth client created with |
force |
A logical indicating whether to force a refresh of the token. |
refresh_token |
A refresh token associated with this |
A YouTube OAuth token, invisibly.
token <- yt_authenticate()
token <- yt_authenticate()
If you use this function, please open an issue in the youtubeR GitHub repository describing your use case. We intend to wrap all endpoints such that this function will not be necessary for users.
yt_call_api( endpoint, query = NULL, body = NULL, method = NULL, client = yt_construct_client(), cache_disk = getOption("youtuberR.cache_disk", FALSE), cache_key = getOption("youtuberR.cache_key", NULL), token = NULL, base_url = c("basic", "upload", "resumable_upload") )
yt_call_api( endpoint, query = NULL, body = NULL, method = NULL, client = yt_construct_client(), cache_disk = getOption("youtuberR.cache_disk", FALSE), cache_key = getOption("youtuberR.cache_key", NULL), token = NULL, base_url = c("basic", "upload", "resumable_upload") )
endpoint |
The path to an endpoint. Optionally, a list with the path
plus variables to |
query |
An optional list of parameters to pass in the query portion of the request. |
body |
An optional list of parameters to pass in the body portion of the request. |
method |
If the method is something other than GET or POST, supply it. Case is ignored. |
client |
A YouTube OAuth client created with |
cache_disk |
Should the access token be cached on disk? This reduces the number of times that you need to re-authenticate at the cost of storing access credentials on disk. Learn more in https://httr2.r-lib.org/articles/oauth.html. |
cache_key |
If you are authenticating with multiple users using the same client, use this key to differentiate between those users. |
token |
A YouTube API OAuth token, or the |
base_url |
Which family of URLs to use. Almost everything will use the default basic URL. |
The result of the call.
Builds the OAuth client object for google apis.
yt_construct_client( client_id = Sys.getenv("YOUTUBE_CLIENT_ID"), client_secret = Sys.getenv("YOUTUBE_CLIENT_SECRET") )
yt_construct_client( client_id = Sys.getenv("YOUTUBE_CLIENT_ID"), client_secret = Sys.getenv("YOUTUBE_CLIENT_SECRET") )
client_id |
A Google Cloud OAuth 2.0 client ID. We
recommend you save it as an environment variable, |
client_secret |
A Google Cloud OAuth 2.0 client secret. We
recommend you save it as an environment variable, |
An httr2::oauth_client()
object.
client <- yt_construct_client()
client <- yt_construct_client()
Reports whether YouTube client environment variables are set (or, if arguments are provided, check that they have characters).
yt_has_client_envvars( client_id = Sys.getenv("YOUTUBE_CLIENT_ID"), client_secret = Sys.getenv("YOUTUBE_CLIENT_SECRET") )
yt_has_client_envvars( client_id = Sys.getenv("YOUTUBE_CLIENT_ID"), client_secret = Sys.getenv("YOUTUBE_CLIENT_SECRET") )
client_id |
A Google Cloud OAuth 2.0 client ID. We
recommend you save it as an environment variable, |
client_secret |
A Google Cloud OAuth 2.0 client secret. We
recommend you save it as an environment variable, |
A logical indicating whether the variables are available.
yt_has_client_envvars() yt_has_client_envvars("an_id_string", "a_secret_string")
yt_has_client_envvars() yt_has_client_envvars("an_id_string", "a_secret_string")
Localized versions of certain video properties (e.g. title).
yt_schema_video_localization(description = character(), title = character())
yt_schema_video_localization(description = character(), title = character())
description |
(character scalar) Localized version of the video's description. |
title |
(character scalar) Localized version of the video's title. |
A list with any non-zero-length properties.
yt_schema_video_localization() yt_schema_video_localization(description = "A description.")
yt_schema_video_localization() yt_schema_video_localization(description = "A description.")
Basic details about a video, including title, description, uploader, thumbnails and category.
yt_schema_video_snippet( title = character(), description = character(), tags = character(), category_id = character(), default_language = character() )
yt_schema_video_snippet( title = character(), description = character(), tags = character(), category_id = character(), default_language = character() )
title |
(character scalar) The video's title. |
description |
(character scalar) The video's description. |
tags |
(character vector) A list of keyword tags associated with the video. Tags may contain spaces. |
category_id |
(character scalar) The YouTube video category associated with the video. |
default_language |
(character scalar) The language of the videos's default snippet. |
A list with any non-zero-length properties.
yt_schema_video_snippet() yt_schema_video_snippet(title = "An example video", tags = c("a", "b"))
yt_schema_video_snippet() yt_schema_video_snippet(title = "An example video", tags = c("a", "b"))
The status object contains information about the video's uploading, processing, and privacy statuses.
yt_schema_video_status( embeddable = logical(), license = character(), privacy_status = character(), public_stats_viewable = logical(), publish_at = datetime(), self_declared_made_for_kids = logical() )
yt_schema_video_status( embeddable = logical(), license = character(), privacy_status = character(), public_stats_viewable = logical(), publish_at = datetime(), self_declared_made_for_kids = logical() )
embeddable |
(logical) This value indicates if the video can be embedded on another website. |
license |
(factor scalar) The video's license. values: youtube, creativeCommon |
privacy_status |
(factor scalar) The video's privacy status. values: public, unlisted, private |
public_stats_viewable |
(logical) This value indicates if the extended video statistics on the watch page can be viewed by everyone. Note that the view count, likes, etc will still be visible if this is disabled. |
publish_at |
(datetime scalar) The date and time when the video is scheduled to publish. It can be set only if the privacy status of the video is private. |
self_declared_made_for_kids |
(logical) Whether the video is made for kids. |
A list with any non-zero-length properties.
yt_schema_video_status() yt_schema_video_status(embeddable = TRUE)
yt_schema_video_status() yt_schema_video_status(embeddable = TRUE)
Deletes a resource.
yt_videos_delete( video_id, client = yt_construct_client(), cache_disk = getOption("youtuberR.cache_disk", FALSE), cache_key = getOption("youtuberR.cache_key", NULL), token = NULL )
yt_videos_delete( video_id, client = yt_construct_client(), cache_disk = getOption("youtuberR.cache_disk", FALSE), cache_key = getOption("youtuberR.cache_key", NULL), token = NULL )
video_id |
(character scalar) The id parameter specifies the YouTube video ID for the resource that is being deleted. In a video resource, the id property specifies the video's ID. |
client |
A YouTube OAuth client created with |
cache_disk |
Should the access token be cached on disk? This reduces the number of times that you need to re-authenticate at the cost of storing access credentials on disk. Learn more in https://httr2.r-lib.org/articles/oauth.html. |
cache_key |
If you are authenticating with multiple users using the same client, use this key to differentiate between those users. |
token |
A YouTube API OAuth token, or the |
The id of the deleted video.
Inserts a new resource into this collection.
yt_videos_insert( video_path, snippet = yt_schema_video_snippet(), localizations = list(), status = yt_schema_video_status(), recording_date = datetime(), client = yt_construct_client(), cache_disk = getOption("youtuberR.cache_disk", FALSE), cache_key = getOption("youtuberR.cache_key", NULL), token = NULL )
yt_videos_insert( video_path, snippet = yt_schema_video_snippet(), localizations = list(), status = yt_schema_video_status(), recording_date = datetime(), client = yt_construct_client(), cache_disk = getOption("youtuberR.cache_disk", FALSE), cache_key = getOption("youtuberR.cache_key", NULL), token = NULL )
video_path |
(character scalar) Path to a video file to upload. |
snippet |
Basic details about a video, including title, description,
uploader, thumbnails and category. See |
localizations |
A list of named localizations objects. The localizations
object contains localized versions of the basic details about the video,
such as its title and description. The name should be a valid language key,
which is a BCP-47 language
code. See |
status |
Basic details about a video category, such as its localized
title. See |
recording_date |
(datetime scalar) The date and time when the video was recorded. |
client |
A YouTube OAuth client created with |
cache_disk |
Should the access token be cached on disk? This reduces the number of times that you need to re-authenticate at the cost of storing access credentials on disk. Learn more in https://httr2.r-lib.org/articles/oauth.html. |
cache_key |
If you are authenticating with multiple users using the same client, use this key to differentiate between those users. |
token |
A YouTube API OAuth token, or the |
The id of the uploaded video.
Updates an existing resource.
yt_videos_update( video_id, snippet = yt_schema_video_snippet(), localizations = list(), status = yt_schema_video_status(), recording_date = datetime(), client = yt_construct_client(), cache_disk = getOption("youtuberR.cache_disk", FALSE), cache_key = getOption("youtuberR.cache_key", NULL), token = NULL )
yt_videos_update( video_id, snippet = yt_schema_video_snippet(), localizations = list(), status = yt_schema_video_status(), recording_date = datetime(), client = yt_construct_client(), cache_disk = getOption("youtuberR.cache_disk", FALSE), cache_key = getOption("youtuberR.cache_key", NULL), token = NULL )
video_id |
(character scalar) The id parameter specifies the YouTube video ID for the resource that is being updated In a video resource, the id property specifies the video's ID. |
snippet |
Basic details about a video, including title, description,
uploader, thumbnails and category. See |
localizations |
A list of named localizations objects. The localizations
object contains localized versions of the basic details about the video,
such as its title and description. The name should be a valid language key,
which is a BCP-47 language
code. See |
status |
Basic details about a video category, such as its localized
title. See |
recording_date |
(datetime scalar) The date and time when the video was recorded. |
client |
A YouTube OAuth client created with |
cache_disk |
Should the access token be cached on disk? This reduces the number of times that you need to re-authenticate at the cost of storing access credentials on disk. Learn more in https://httr2.r-lib.org/articles/oauth.html. |
cache_key |
If you are authenticating with multiple users using the same client, use this key to differentiate between those users. |
token |
A YouTube API OAuth token, or the |
The id of the updated video.