API 요청 매개변수와 일치하는 동영상의 목록을 반환합니다. 지금 사용해 보거나 예를 참조하세요.
요청
HTTP 요청
GET https://www.googleapis.com/youtube/v3/videos
매개변수
아래 표는 이 쿼리가 지원하는 매개변수 목록입니다. 나열된 모든 매개변수는 쿼리 매개변수입니다.
매개변수 이름 | ||
---|---|---|
필수 매개변수 | ||
part |
string part 매개변수는 API 응답이 포함하는 video 리소스 속성 하나 이상의 쉼표로 구분된 목록을 지정합니다. 매개변수 값에 포함할 수 있는 part 이름은 id , snippet , contentDetails , fileDetails , liveStreamingDetails , player , processingDetails , recordingDetails , statistics , status , suggestions , topicDetails 입니다.매개변수가 하위 속성을 포함하는 속성을 식별하는 경우 하위 속성이 응답에 포함됩니다. 예를 들어 video 리소스에서 snippet 속성은 channelId , title , description , tags , categoryId 속성을 포함합니다. 따라서 part=snippet 을 설정하는 경우 API 응답은 하위 속성도 모두 포함합니다. |
|
필터(다음 매개변수 중 하나만 지정합니다.) | ||
chart |
string chart 매개변수는 검색하려는 차트를 식별합니다.허용값은 다음과 같습니다. |
|
id |
string id 매개변수는 검색되는 리소스에 대한 YouTube 동영상 ID의 쉼표로 구분된 목록을 지정합니다. video 리소스에서 id 속성은 동영상의 ID를 지정합니다. |
|
myRating |
string 이 매개변수는 제대로 인증된 요청에서만 사용할 수 있습니다. 이 매개변수의 값을 like 또는 dislike 로 설정하여 인증된 사용자가 좋아요 또는 싫어요 표시한 동영상만 API에서 반환하게 합니다.허용값은 다음과 같습니다.
|
|
선택적 매개변수 | ||
maxResults |
unsigned integer maxResults 매개변수는 결과 집합에 반환해야 하는 최대 항목 수를 지정합니다.참고: 이 매개변수는 myRating 매개변수와 함께 사용하도록 지원되지만 id 매개변수와 함께 사용하도록 지원되지는 않습니다. 허용값은 1 이상 50 이하입니다. 기본값은 5 입니다. |
|
onBehalfOfContentOwner |
string 이 매개변수는 제대로 인증된 요청에서만 사용할 수 있습니다. 참고: 이 매개변수는 YouTube 콘텐츠 파트너 전용입니다. onBehalfOfContentOwner 매개변수는 요청의 승인 사용자 인증 정보가 매개변수 값에 지정된 콘텐츠 소유자를 대신하는 YouTube CMS 사용자를 확인함을 나타냅니다. 이 매개변수는 다양한 여러 YouTube 채널을 소유하고 관리하는 YouTube 콘텐츠 파트너 전용입니다. 이 매개변수로 콘텐츠 소유자는 각 개별 채널에 승인 사용자 인증 정보를 제공할 필요 없이 한 번 인증하여 모든 동영상 및 채널 데이터에 액세스할 수 있습니다. 사용자가 인증할 CMS 계정은 지정된 YouTube 콘텐츠 소유자에게 연결되어야 합니다. |
|
pageToken |
string pageToken 매개변수는 반환해야 하는 결과 집합의 특정 페이지를 식별합니다. API 응답에서 nextPageToken 및 prevPageToken 속성은 검색할 기타 페이지를 식별합니다.참고: 이 매개변수는 myRating 매개변수와 함께 사용하도록 지원되지만 id 매개변수와 함께 사용하도록 지원되지는 않습니다. |
|
regionCode |
string regionCode 매개변수는 API가 지정된 지역에서 사용할 수 있는 동영상 차트를 선택하도록 합니다. 이 매개변수를 사용하는 경우 차트 또한 설정해야 합니다. 이 매개변수 값은 ISO 3166-1 alpha-2 국가 코드입니다. |
|
videoCategoryId |
string videoCategoryId 매개변수는 차트를 검색해야 할 동영상 카테고리를 식별합니다. 이 매개변수는 chart 매개변수와만 함께 사용할 수 있습니다. 기본적으로 차트는 특정 카테고리에 제한되지 않습니다. 기본값은 0 입니다. |
요청 본문
이 메소드를 호출할 때 요청 본문을 제공하지 마세요.
응답
성공하는 경우 이 메소드는 다음 구조로 응답 본문을 반환합니다.
{ "kind": "youtube#videoListResponse", "etag": etag, "nextPageToken": string, "prevPageToken": string, "pageInfo": { "totalResults": integer, "resultsPerPage": integer }, "items": [ video Resource ] }
속성
다음 표는 이 리소스에 표시되는 속성을 정의합니다.
속성 이름 | |
---|---|
kind |
string API 리소스의 유형입니다. 값은 youtube#videoListResponse 가 됩니다. |
etag |
etag 이 리소스의 Etag입니다. |
nextPageToken |
string pageToken 매개변수의 값으로 사용하여 결과 집합의 다음 페이지를 검색할 수 있는 토큰입니다. |
prevPageToken |
string pageToken 매개변수의 값으로 사용하여 결과 집합의 이전 페이지를 검색할 수 있는 토큰입니다. |
pageInfo |
object pageInfo 개체는 결과 집합의 페이지 정보를 요약합니다. |
pageInfo.totalResults |
integer 결과 집합의 총 결과 수입니다. |
pageInfo.resultsPerPage |
integer API 응답에 포함된 결과 수입니다. |
items[] |
list 요청 기준과 일치하는 동영상의 목록입니다. |
예
참고: 아래의 코드 샘플은 지원되는 일부 프로그래밍 언어를 나타냅니다. 지원되는 언어 목록을 보려면 클라이언트 라이브러리 문서를 참조하세요.
PHP
PHP 클라이언트 라이브러리를 사용하는 예입니다.
<?php /** * This sample adds new tags to a YouTube video by: * * 1. Retrieving the video resource by calling the "youtube.videos.list" method * and setting the "id" parameter * 2. Appending new tags to the video resource's snippet.tags[] list * 3. Updating the video resource by calling the youtube.videos.update method. * * @author Ibrahim Ulukaya */ /** * Library Requirements * * 1. Install composer (https://getcomposer.org) * 2. On the command line, change to this directory (api-samples/php) * 3. Require the google/apiclient library * $ composer require google/apiclient:~2.0 */ if (!file_exists(__DIR__ . '/vendor/autoload.php')) { throw new \Exception('please run "composer require google/apiclient:~2.0" in "' . __DIR__ .'"'); } require_once __DIR__ . '/vendor/autoload.php'; session_start(); /* * You can acquire an OAuth 2.0 client ID and client secret from the * Google API Console <https://console.developers.google.com/> * For more information about using OAuth 2.0 to access Google APIs, please see: * <https://developers.google.com/youtube/v3/guides/authentication> * Please ensure that you have enabled the YouTube Data API for your project. */ $OAUTH2_CLIENT_ID = 'REPLACE_ME'; $OAUTH2_CLIENT_SECRET = 'REPLACE_ME'; $client = new Google_Client(); $client->setClientId($OAUTH2_CLIENT_ID); $client->setClientSecret($OAUTH2_CLIENT_SECRET); $client->setScopes('https://www.googleapis.com/auth/youtube'); $redirect = filter_var('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'], FILTER_SANITIZE_URL); $client->setRedirectUri($redirect); // Define an object that will be used to make all API requests. $youtube = new Google_Service_YouTube($client); // Check if an auth token exists for the required scopes $tokenSessionKey = 'token-' . $client->prepareScopes(); if (isset($_GET['code'])) { if (strval($_SESSION['state']) !== strval($_GET['state'])) { die('The session state did not match.'); } $client->authenticate($_GET['code']); $_SESSION[$tokenSessionKey] = $client->getAccessToken(); header('Location: ' . $redirect); } if (isset($_SESSION[$tokenSessionKey])) { $client->setAccessToken($_SESSION[$tokenSessionKey]); } // Check to ensure that the access token was successfully acquired. if ($client->getAccessToken()) { $htmlBody = ''; try{ // REPLACE this value with the video ID of the video being updated. $videoId = "VIDEO_ID"; // Call the API's videos.list method to retrieve the video resource. $listResponse = $youtube->videos->listVideos("snippet", array('id' => $videoId)); // If $listResponse is empty, the specified video was not found. if (empty($listResponse)) { $htmlBody .= sprintf('<h3>Can\'t find a video with video id: %s</h3>', $videoId); } else { // Since the request specified a video ID, the response only // contains one video resource. $video = $listResponse[0]; $videoSnippet = $video['snippet']; $tags = $videoSnippet['tags']; // Preserve any tags already associated with the video. If the video does // not have any tags, create a new list. Replace the values "tag1" and // "tag2" with the new tags you want to associate with the video. if (is_null($tags)) { $tags = array("tag1", "tag2"); } else { array_push($tags, "tag1", "tag2"); } // Set the tags array for the video snippet $videoSnippet['tags'] = $tags; // Update the video resource by calling the videos.update() method. $updateResponse = $youtube->videos->update("snippet", $video); $responseTags = $updateResponse['snippet']['tags']; $htmlBody .= "<h3>Video Updated</h3><ul>"; $htmlBody .= sprintf('<li>Tags "%s" and "%s" added for video %s (%s) </li>', array_pop($responseTags), array_pop($responseTags), $videoId, $video['snippet']['title']); $htmlBody .= '</ul>'; } } catch (Google_Service_Exception $e) { $htmlBody .= sprintf('<p>A service error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage())); } catch (Google_Exception $e) { $htmlBody .= sprintf('<p>An client error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage())); } $_SESSION[$tokenSessionKey] = $client->getAccessToken(); } elseif ($OAUTH2_CLIENT_ID == 'REPLACE_ME') { $htmlBody = <<<END <h3>Client Credentials Required</h3> <p> You need to set <code>\$OAUTH2_CLIENT_ID</code> and <code>\$OAUTH2_CLIENT_ID</code> before proceeding. <p> END; } else { // If the user hasn't authorized the app, initiate the OAuth flow $state = mt_rand(); $client->setState($state); $_SESSION['state'] = $state; $authUrl = $client->createAuthUrl(); $htmlBody = <<<END <h3>Authorization Required</h3> <p>You need to <a href="$authUrl">authorize access</a> before proceeding.<p> END; } ?> <!doctype html> <html> <head> <title>Video Updated</title> </head> <body> <?=$htmlBody?> </body> </html>
오류
아래 표에서는 이 메소드에 대한 호출에 응답하기 위해 API가 반환할 수 있는 오류 메시지를 식별합니다. 자세한 내용은 오류 메시지 설명서를 참조하세요.
오류 유형 | 오류 세부정보 | 설명 |
---|---|---|
badRequest |
videoChartNotFound |
요청한 동영상 차트가 지원되지 않거나 동영상 차트를 사용할 수 없습니다. |
forbidden |
forbidden |
요청이 평점 정보에 액세스할 수 없습니다. 요청이 myRating 매개변수를 사용하도록 제대로 인증되지 않은 경우 이 오류가 발생할 수 있습니다. |
직접 사용해 보세요!
API Explorer를 사용하여 실시간 데이터에서 이 메소드를 호출하고 API 요청 및 응답을 확인해 보세요.