본문 바로가기

Back-end/Server

[ YoutubeAPI ] YouTube Data API v3: /videos list 메서드 사용 하기

 

https://blog.naver.com/nagiiii/223291184237 (이미지 출처)

 

 

API 홈

https://developers.google.com/youtube?hl=ko

 

YouTube  |  Google for Developers

사이트 및 앱에 YouTube 기능을 추가하세요.

developers.google.com

 

 

 

 

🎈Youtube Data API v3: /videos list 메서드 사용하기

 

 

API Key 발급 

https://console.cloud.google.com/

 

Google 클라우드 플랫폼

로그인 Google 클라우드 플랫폼으로 이동

accounts.google.com

 

Youtube API를 사용할려면 Google Cloud Console에서 API 키를 발급받아야 한다 

 

 

쿼터 제한

기본적으로 하루 10,000 쿼터가 제공 
- /videos 요청당 1쿼터 적용

 

 

 

API Base Url

https://www.googleapis.com/youtube/v3

 

 

 

 

 

📽️ /videos 엔드포인트

/videos 엔드포인트는 특정 동영상의 상세 정보를 가져오는데 사용 

인기 동영상 목록 조회도 가능하며, 동영상의 메타데이터(조회수, 좋아요 수 등)를 확인할 수 있다

 

 

HTTP 요청

GET https://www.googleapis.com/youtube/v3/videos

 

 

 

파라미터

 필수 파라미터
 part  반환할 데이터의 종류를 지정, snippet, statistics, contentDetails 등을 포함
 key  API Key
 필터 (다음 파라미터 중 하나만 지정)
 chart  인기 동영상 조회 시 사용, 값으로 mostPpular 지정
 id  조회할 동영상의 ID, 여러 개를 쉼표로 구분해 검색 가능
 myRating  자신의 Youtube 계정에서 평가한 동영상을 검색할 때 사용, dislike(싫어요), like(좋아요)
 선택 파라미터 (제일 자주 사용하는 파라미터 몇 가지)
 maxResults  반환할 결과의 최대 개수, 기본값 5, 최대값 50
 regionCode  특정 국가에서 인기 있는 목록을 조회할 때 사용, ISO 3166-1 alpha-2 국가코드  (한국: KR)
 videoCategoryId  특정 카테고리에 속하는 동영상만 필터링할 때 사용, (영화및애니메이션: 1, 음악: 10, 게임: 20 ...)

 

part 파라미터

쉼표 사용하여 선택 가능

  • snippet: 제목, 설명, 채널 이름 등 기본 정보 포함
  • statistics: 조회수, 좋아요 수 등 메타데이터
  • contentDetails: 동영상 길이 등 콘텐츠 세부 정보

 

 

 

예시: 한국 지역 인기 동영상 목록 가져오기

GET https://www.googleapis.com/youtube/v3/videos
  ?part=snippet,statistics
  &chart=mostPopular
  &regionCode=KR
  &maxResults=10
  &key=YOUR_API_KEY

 

 

예시: 특정 동영상 정보 조회

GET https://www.googleapis.com/youtube/v3/videos
  ?part=snippet,statistics
  &id=동영상ID
  &key=YOUR_API_KEY

 

 

예시 : response Data

{
  "kind": "youtube#videoListResponse",
  "etag": "etag_value",
  "items": [
    {
      "kind": "youtube#video",
      "etag": "etag_value",
      "id": "abcd1234",  // 동영상 ID
      "snippet": {
        "publishedAt": "2024-11-20T12:34:56Z",  // 업로드 날짜
        "channelId": "channel1234",  // 채널 ID
        "title": "Popular Video Title",  // 동영상 제목
        "description": "This is a description of the video.",  // 동영상 설명
        "thumbnails": {  // 썸네일 이미지
          "default": {
            "url": "https://i.ytimg.com/vi/abcd1234/default.jpg",
            "width": 120,
            "height": 90
          },
          "medium": {
            "url": "https://i.ytimg.com/vi/abcd1234/mqdefault.jpg",
            "width": 320,
            "height": 180
          },
          "high": {
            "url": "https://i.ytimg.com/vi/abcd1234/hqdefault.jpg",
            "width": 480,
            "height": 360
          }
        },
        "channelTitle": "Channel Name",  // 채널 이름
        "tags": ["tag1", "tag2"],  // 동영상 태그 (있을 경우)
        "categoryId": "10",  // 동영상 카테고리 ID (예: 음악)
        "liveBroadcastContent": "none",  // 라이브 방송 여부
        "localized": {
          "title": "Localized Title",
          "description": "Localized description of the video."
        }
      },
      "statistics": {
        "viewCount": "1234567",  // 조회수
        "likeCount": "89012",  // 좋아요 수
        "favoriteCount": "0",  // 즐겨찾기 수 (항상 0으로 반환됨)
        "commentCount": "4567"  // 댓글 수
      }
    }
  ],
  "nextPageToken": "pageToken",
  "pageInfo": {
    "totalResults": 100,  // 검색 결과 총 개수 (이 경우 인기 동영상의 전체 수)
    "resultsPerPage": 10  // 요청당 반환된 동영상 수
  }
}

 

 

Youtube Music API는 없지만 Youtube API 통하여 음악 데이터를 가져올 수 있다