https://developers.google.com/youtube/v3/docs/playlistItems/list?hl=ko
search와는 다르게 할당량이 1이다! 플레이리스트만 가지고 올 수 있다면 괜찮은 선택
물론 기본 플레이리스트인 uploads
가 존재하므로, 플레이리스트 기반으로 가져올 수 있다.
카테고리 | 할당량 | 쿼리당 최대 반환 개수 | 최대 검색 개수 |
---|---|---|---|
playlistItems:list |
1 | 50 | 20000(일반인은 거의 무한) |
search:list |
100 | 50 | 500, |
1,000,000(자신의 동영상, 추정) |
실제로 playlist 기반으로 가져올 경우, 2000개가 넘는 영상 목록을 불러올 수 있다.
# google의 업로드된 동영상의 개수
"pageInfo": {
"totalResults": 2152,
"resultsPerPage": 5
}
# T-Series의 업로드된 동영상의 개수.
# 25/02/26 기준으로 22641개지만 최대 2만개까지 가져오는 것을 확인할 수 있다.
"pageInfo": {
"totalResults": 20000,
"resultsPerPage": 5
}
<aside> ⚙
Request
</aside>
URL: <https://www.googleapis.com/youtube/v3/playlistItems>
METHOD: GET
HEADERS:
- Authorization: Bearer [ACCESS_TOKEN]
- Accept: application/json
QUERIES:
- key: [MY_API_KEY]
- part: snippet
- playlistId: [playlist id]
- maxResults: 50 (default 5)
- pageToken?: [이전 요청의 pageToken]
<aside> ⚙
Response
</aside>
{
"kind": "youtube#playlistItemListResponse",
"etag": etag,
"nextPageToken": string,
"prevPageToken": string,
"pageInfo": {
"totalResults": integer,
"resultsPerPage": integer
},
"items": [
playlistItem Resource
]
}
playlistItemResoutce: {
"kind": "youtube#playlistItem",
"etag": etag,
"id": string,
"snippet": {
...
"publishedAt": datetime,
"title": string,
"description": string,
"thumbnails": {
(key): { // <- key는 default, medium, high, standard, maxres가 존재
"url": string,
"width": unsigned integer,
"height": unsigned integer
}
},
...
"resourceId": {
"kind": string,
"videoId": string,
}
},
"contentDetails": { // <- part에 contentDetais를 넣었을때 적용됨
"videoId": string,
"startAt": string,
"endAt": string,
"note": string,
"videoPublishedAt": datetime
},
...
}
실질적으로 쓰는 것은
1. nextPageToken: response.data.nextPageToken
2. videos: response.data.items
3. videoInfos: videos.map((video) => ({
id: video.snippet.resourceId.videoId,
title: video.snippet.title,
description: video.snippet.description,
thumbnail: video.snippet.thumbnails[KEY].url,
publishedAt: video.snippet.publishedAt,
}))