YouTube
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
동영상 세부정보 업데이트
function updateYouTubeVideo() {
// 1. Fetch all the channels owned by active user.
var myChannels = YouTube.Channels.list('contentDetails', {mine: true});
// 2. Iterate through the channels and get the uploads playlist ID.
for (var i = 0; i < myChannels.items.length; i++) {
var item = myChannels.items[i];
var uploadsPlaylistId = item.contentDetails.relatedPlaylists.uploads;
var playlistResponse = YouTube.PlaylistItems.list('snippet', {
playlistId: uploadsPlaylistId,
maxResults: 1
});
// Get the ID of the first video in the list.
var video = playlistResponse.items[0];
var originalDescription = video.snippet.description;
var updatedDescription = originalDescription +
' Description updated via Google Apps Script';
video.snippet.description = updatedDescription;
var resource = {
snippet: {
title: video.snippet.title,
description: updatedDescription,
categoryId: '22'
},
id: video.snippet.resourceId.videoId
};
YouTube.Videos.update(resource, 'id,snippet');
console.log('Video with ID = %s and Title = %s was successfully updated.',
video.snippet.resourceId.videoId, video.snippet.title);
}
}
채널 게시판 만들기
function postChannelBulletin() {
var message = 'Thanks for subscribing to my channel! This posting is ' +
'from Google Apps Script';
var videoId = 'INSERT_VIDEO_ID_HERE';
var resource = {
snippet: {
description: message
},
contentDetails: {
bulletin: {
resourceId: {
kind: 'youtube#video',
videoId: videoId
}
}
}
};
var response = YouTube.Activities.insert(resource, 'snippet,contentDetails');
console.log('Posted to channel bulletin successfully.');
}
동영상 업로드 가져오기
function retrieveVideoUploads() {
var results = YouTube.Channels.list('contentDetails', {mine: true});
for (var i in results.items) {
var item = results.items[i];
// Get the playlist ID, which is nested in contentDetails, as described in
// the Channel resource:
// https://developers.google.com/youtube/v3/docs/channels
var playlistId = item.contentDetails.relatedPlaylists.uploads;
var nextPageToken = '';
// This loop retrieves a set of playlist items and checks the nextPageToken
// in the response to determine whether the list contains additional items.
// It repeats that process until it has retrieved all of the items in the
// list.
while (nextPageToken != null) {
var playlistResponse = YouTube.PlaylistItems.list('snippet', {
playlistId: playlistId,
maxResults: 25,
pageToken: nextPageToken
});
for (var j = 0; j < playlistResponse.items.length; j++) {
var playlistItem = playlistResponse.items[j];
console.log('[%s] Title: %s',
playlistItem.snippet.resourceId.videoId,
playlistItem.snippet.title);
}
nextPageToken = playlistResponse.nextPageToken;
}
}
}
키워드별 동영상 검색
function searchVideosByKeyword() {
var results = YouTube.Search.list('id,snippet', {q: 'dogs', maxResults: 25});
for (var i in results.items) {
var item = results.items[i];
console.log('[%s] Title: %s', item.id.videoId, item.snippet.title);
}
}
주제별 동영상 검색
function searchVideosByFreebaseTopic() {
// See https://developers.google.com/youtube/v3/guides/searching_by_topic
// for more details.
// Insert Your Freebase topic ID here. The Freebase ID used in this example
// corresponds to the Freebase entry for Google. See
// http://www.freebase.com/m/045c7b for more details.
var mid = '/m/045c7b';
var results = YouTube.Search.list('id,snippet',
{topicId: mid, maxResults: 25});
for (var i in results.items) {
var item = results.items[i];
console.log('[%s] Title: %s', item.id.videoId, item.snippet.title);
}
}
채널 구독
function subscribeToChannel() {
// Replace this channel ID with the channel ID you want to subscribe to.
var channelId = 'INSERT_YOUTUBE_CHANNEL_ID_HERE';
var resource = {
snippet: {
resourceId: {
kind: 'youtube#channel',
channelId: channelId
}
}
};
try {
var response = YouTube.Subscriptions.insert(resource, 'snippet');
console.log('Subscribed to channel ID %s successfully.', channelId);
} catch (e) {
if (e.message.match('subscriptionDuplicate')) {
console.log('Cannot subscribe; already subscribed to channel: ' +
channelId);
} else {
console.log('Error adding subscription: ' + e.message);
}
}
}
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-03-17(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-03-17(UTC)"],[[["This script provides functionalities for managing YouTube channels and videos, such as updating video details, posting channel bulletins, and retrieving video uploads."],["Users can leverage the provided functions to find videos based on keywords or Freebase topics."],["The script allows for subscribing to channels and managing channel subscriptions, handling potential duplicate subscriptions."],["It demonstrates the usage of Google Apps Script to interact with the YouTube API for automating channel and video management tasks."]]],[]]