Documentation
Library Exports.YouTube
The main class used to interact with the YouTube API. Use this.
Constructors
constructor
• new YouTube(apiKey?
, accessToken?
, options?
, language?
, region?
)
Parameters
Name | Type | Default value | Description |
---|---|---|---|
apiKey? | string | undefined | Your YouTube Data API v3 key. Don't share this with anybody. |
accessToken? | string | undefined | A Google OAuth 2.0 access token. Used for YouTube.oauth methods. |
options | YouTubeOptions | undefined | Caching options. Recommended to change. |
language | string | 'en_US' | The language for the API to respond in. See YouTube.getLanguages() . |
region | string | 'US' | The region for the API cater responses to. See YouTube.getRegions() .. |
Defined in
Properties
#auth
• Private
#auth: Authorization
= {}
Defined in
language
• language: string
The language for the API to respond in. See YouTube.getLanguages()
.
Defined in
oauth
• oauth: OAuth
Methods requiring an OAuth token.
Defined in
region
• region: string
The region for the API cater responses to. See YouTube.getRegions()
.
Defined in
Methods
getCategories
▸ getCategories(): Promise
<VideoCategory
[]>
Get the list of video categories in this.region
`.
Returns
Promise
<VideoCategory
[]>
Defined in
getCategory
▸ getCategory<T
>(categoryId
): Promise
<ItemReturns
<T
, typeof VideoCategory
>>
Get a VideoCategory
object from the ID of a category.
Type parameters
Name | Type |
---|---|
T | extends string | string [] |
Parameters
Name | Type | Description |
---|---|---|
categoryId | T | The ID of the category. |
Returns
Promise
<ItemReturns
<T
, typeof VideoCategory
>>
Defined in
getChannel
▸ getChannel<T
>(channelResolvable
, parts?
): Promise
<ItemReturns
<ResolveReturn
<T
, typeof Channel
>, typeof Channel
>>
Get a Channel
object from the URL, ID, search query, or handle of a channel.
Beware, support for old custom channel URLs is shoddy.
Consider migrating to the new @ system.
Type parameters
Name | Type |
---|---|
T | extends ChannelResolvable | ChannelResolvable [] |
Parameters
Name | Type | Description |
---|---|---|
channelResolvable | T | The URL, ID, search query, or handle of the channel. |
parts? | ChannelParts | The parts of the channel to fetch (saves quota if you aren't using certain properties!) |
Returns
Promise
<ItemReturns
<ResolveReturn
<T
, typeof Channel
>, typeof Channel
>>
Defined in
getChannelPlaylists
▸ getChannelPlaylists(channelResolvable
, pageOptions?
, parts?
): Promise
<PaginatedResponse
<Playlist
>>
Get maxPerPage * pages
of a Channel
's Playlist
s.
Used mostly internally with Channel.fetchPlaylists()
.
Parameters
Name | Type | Description |
---|---|---|
channelResolvable | ChannelResolvable | The Username, URL, or ID of the channel. |
pageOptions? | PageOptions | The number of pages and maximum number of items per page. Fetches the maximum number of items allowed by the API per page by default. Set pages to a value <=0 to fetch all. |
parts? | PlaylistParts | The parts of the playlists to fetch (saves quota if you aren't using certain properties!) |
Returns
Promise
<PaginatedResponse
<Playlist
>>
An object containing page token information for future requests and playlist objects.
Defined in
getChannelSection
▸ getChannelSection<T
>(sectionId
, parts?
): Promise
<ItemReturns
<T
, typeof ChannelSection
>>
Get a ChannelSection
object from the ID of a section.
Type parameters
Name | Type |
---|---|
T | extends string | string [] |
Parameters
Name | Type | Description |
---|---|---|
sectionId | T | - |
parts? | ChannelSectionParts | The parts of the channel section to fetch (saves quota if you aren't using certain properties!) |
Returns
Promise
<ItemReturns
<T
, typeof ChannelSection
>>
Defined in
getChannelSections
▸ getChannelSections(channelResolvable
, parts?
): Promise
<ChannelSection
[]>
Gets the ChannelSection
s of a Channel
.
Used mostly internally with Channel.fetchSections
.
Parameters
Name | Type | Description |
---|---|---|
channelResolvable | ChannelResolvable | The Username, URL, or ID of the channel to get the sections from. |
parts? | ChannelSectionParts | The parts of the channel sections to fetch (saves quota if you aren't using certain properties!) |
Returns
Promise
<ChannelSection
[]>
Partial channel section objects.
Defined in
getChannelSubscriptions
▸ getChannelSubscriptions(channelResolvable
, pageOptions?
, parts?
): Promise
<PaginatedResponse
<Subscription
>>
Get maxPerPage * pages
of a Channel
's Subscription
s.
Used mostly internally with Channel.fetchSubscriptions()
.
Parameters
Name | Type | Description |
---|---|---|
channelResolvable | ChannelResolvable | The Username, URL, or ID of the channel. |
pageOptions? | PageOptions | The number of pages and maximum number of items per page. Fetches the maximum number of items allowed by the API per page by default. Set pages to a value <=0 to fetch all. |
parts? | SubscriptionParts | The parts of the subscriptions to fetch (saves quota if you aren't using certain properties!) |
Returns
Promise
<PaginatedResponse
<Subscription
>>
An object containing page token information for future requests and subscription objects.
Defined in
getComment
▸ getComment<T
>(commentId
, parts?
): Promise
<ItemReturns
<T
, typeof Comment
>>
Get a Comment
object from the ID of a comment.
Type parameters
Name | Type |
---|---|
T | extends string | string [] |
Parameters
Name | Type | Description |
---|---|---|
commentId | T | The ID of the comment. |
parts? | CommentParts | The parts of the comment to fetch (saves quota if you aren't using certain properties!) |
Returns
Promise
<ItemReturns
<T
, typeof Comment
>>
Defined in
getCommentReplies
▸ getCommentReplies(commentResolvable
, pageOptions?
, parts?
): Promise
<PaginatedResponse
<Comment
>>
Get maxPerPage * pages
replies to a Comment
.
Used mostly internally with Comment.fetchReplies
.
Parameters
Name | Type | Description |
---|---|---|
commentResolvable | CommentResolvable | - |
pageOptions? | PageOptions | The number of pages and maximum number of items per page. Fetches the maximum number of items allowed by the API per page by default. Set pages to a value <=0 to fetch all. |
parts? | CommentParts | The parts of the replies to fetch (saves quota if you aren't using certain properties!) |
Returns
Promise
<PaginatedResponse
<Comment
>>
An object containing page token information for future requests and comment objects.
Defined in
getLanguages
▸ getLanguages(): Promise
<Language
[]>
Get a list of languages that YouTube supports.
Returns
Promise
<Language
[]>
Defined in
getPlaylist
▸ getPlaylist<T
>(playlistResolvable
, parts?
): Promise
<ItemReturns
<ResolveReturn
<T
, typeof Playlist
>, typeof Playlist
>>
Get a Playlist
object from the URL, ID, or search query of a playlist.
Meant mostly for getting by URL or ID.
Type parameters
Name | Type |
---|---|
T | extends PlaylistResolvable | PlaylistResolvable [] |
Parameters
Name | Type | Description |
---|---|---|
playlistResolvable | T | The URL, ID, or search query of the playlist. |
parts? | PlaylistParts | The parts of the playlist to fetch (saves quota if you aren't using certain properties!) |
Returns
Promise
<ItemReturns
<ResolveReturn
<T
, typeof Playlist
>, typeof Playlist
>>
Defined in
getPlaylistItems
▸ getPlaylistItems(playlistResolvable
, pageOptions?
, parts?
): Promise
<PaginatedResponse
<Video
>>
Get maxPerPage * pages
videos in a Playlist
.
Used mostly internally with Playlist.fetchVideos()
.
Parameters
Name | Type | Description |
---|---|---|
playlistResolvable | PlaylistResolvable | The URL, ID, or Title of the playlist. |
pageOptions? | PageOptions | The number of pages and maximum number of items per page. Fetches the maximum number of items allowed by the API per page by default. Set pages to a value <=0 to fetch all. |
parts? | PlaylistItemParts | The parts of the videos to fetch (saves quota if you aren't using certain properties!) |
Returns
Promise
<PaginatedResponse
<Video
>>
An object containing page token information for future requests and partial video objects.
Defined in
getRegions
▸ getRegions(): Promise
<Region
[]>
Get a list of regions that YouTube supports.
Returns
Promise
<Region
[]>
Defined in
getSubscription
▸ getSubscription<T
>(subscriptionId
, parts?
): Promise
<ItemReturns
<T
, typeof Subscription
>>
Get a Subscription
object from the ID of a subscription.
Fetching a subscription by ID is CURRENTLY BROKEN in the Public YouTube API,
see https://issuetracker.google.com/issues/288609601
Type parameters
Name | Type |
---|---|
T | extends string | string [] |
Parameters
Name | Type | Description |
---|---|---|
subscriptionId | T | The ID of the subscription. |
parts? | SubscriptionParts | The parts of the subscription to fetch (saves quota if you aren't using certain properties!) |
Returns
Promise
<ItemReturns
<T
, typeof Subscription
>>
Defined in
getSubscriptionByChannels
▸ getSubscriptionByChannels(subscriberResolvable
, channelResolvable
, parts?
): Promise
<Subscription
>
Get a Subscription
object from the subscriber and channel of a subscription.
Channels can be passed in the form of ID, URL, or search query.
Parameters
Name | Type | Description |
---|---|---|
subscriberResolvable | ChannelResolvable | A resolvable channel that is the subscriber. |
channelResolvable | ChannelResolvable | A resolvable channel that is the channel being subscribed to. |
parts? | SubscriptionParts | The parts of the subscription to fetch (saves quota if you aren't using certain properties!) |
Returns
Promise
<Subscription
>
Defined in
getVideo
▸ getVideo<T
>(videoResolvable
, parts?
): Promise
<ItemReturns
<ResolveReturn
<T
, typeof Video
>, typeof Video
>>
Get a Video
object from the URL, ID, or search query of a video.
Type parameters
Name | Type |
---|---|
T | extends VideoResolvable | VideoResolvable [] |
Parameters
Name | Type | Description |
---|---|---|
videoResolvable | T | The URL, ID, or search query of the video. |
parts? | VideoParts | The parts of the video to fetch (saves quota if you aren't using certain properties!) |
Returns
Promise
<ItemReturns
<ResolveReturn
<T
, typeof Video
>, typeof Video
>>
Defined in
getVideoComments
▸ getVideoComments(videoResolvable
, pageOptions?
, order?
, parts?
): Promise
<PaginatedResponse
<Comment
>>
Get maxPerPage * pages
Comment
s from a Video
.
Used mostly internally with Video.fetchComments()
.
Parameters
Name | Type | Description |
---|---|---|
videoResolvable | VideoResolvable | The URL, ID, or Title of the video. |
pageOptions? | PageOptions | The number of pages and maximum number of items per page. Fetches the maximum number of items allowed by the API per page by default. Set pages to a value <=0 to fetch all. |
order? | "time" | "relevance" | - |
parts? | CommentThreadParts | The parts of the comments to fetch (saves quota if you aren't using certain properties!) |
Returns
Promise
<PaginatedResponse
<Comment
>>
An object containing page token information for future requests and comment objects.
Defined in
hasAccessToken
▸ hasAccessToken(): boolean
Returns
boolean
Defined in
search
▸ search<T
>(searchTerm
, searchOptions?
): Promise
<PaginatedResponse
<InstanceType
<T
>>>
Search supported entities on YouTube.
Type parameters
Name | Type |
---|---|
T | extends SearchType = SearchType |
Parameters
Name | Type | Description |
---|---|---|
searchTerm | string | What to search for on YouTube. |
searchOptions? | GenericSearchOptions <T > | Options related to the search including search filters, the number of pages, maximum number of results per page, and starting page token. Defaults to the maximum 50 items per page, as well as 1 page. Increase pages as high as you'd like. |
Returns
Promise
<PaginatedResponse
<InstanceType
<T
>>>
Defined in
searchChannels
▸ searchChannels(searchTerm
, searchOptions?
): Promise
<PaginatedResponse
<Channel
>>
Search channels on YouTube.
Parameters
Name | Type | Description |
---|---|---|
searchTerm | string | What to search for on YouTube. |
searchOptions? | EntitySearchOptions <typeof Channel > | Options related to the search including search filters, the number of pages, maximum number of results per page, and starting page token. Defaults to the maximum 50 items per page, as well as 1 page. Increase pages as high as you'd like. |
Returns
Promise
<PaginatedResponse
<Channel
>>
Defined in
searchPlaylists
▸ searchPlaylists(searchTerm
, searchOptions?
): Promise
<PaginatedResponse
<Playlist
>>
Search playlists on YouTube.
Parameters
Name | Type | Description |
---|---|---|
searchTerm | string | What to search for on YouTube. |
searchOptions? | EntitySearchOptions <typeof Playlist > | Options related to the search including search filters, the number of pages, maximum number of results per page, and starting page token. Defaults to the maximum 50 items per page, as well as 1 page. Increase pages as high as you'd like. |
Returns
Promise
<PaginatedResponse
<Playlist
>>
Defined in
searchVideos
▸ searchVideos(searchTerm
, searchOptions?
): Promise
<PaginatedResponse
<Video
>>
Search videos on YouTube.
Parameters
Name | Type | Description |
---|---|---|
searchTerm | string | What to search for on YouTube. |
searchOptions? | EntitySearchOptions <typeof Video > | Options related to the search including search filters, the number of pages, maximum number of results per page, and starting page token. Defaults to the maximum 50 items per page, as well as 1 page. Increase pages as high as you'd like. |
Returns
Promise
<PaginatedResponse
<Video
>>
Defined in
setAuthorization
▸ setAuthorization(authorization
): void
Parameters
Name | Type |
---|---|
authorization | Authorization |
Returns
void