YoutubeDataAPI

プログラミング
Search  |  YouTube Data API  |  Google for Developers
GASでYouTubeのデータを取得してスプレッドシートに表示する方法を解説!
GAS(Google Apps Script)でYouTubeのデータを取得してスプレッドシートに表示する方法を解説します.
function myFunction() {
  
}

function searchByKeyword() {
  // データを取得
  const results = YouTube.Search.list('snippet', {
    q: 'ChatGPT',
    maxResults: 10
  });

  // 追加(アクティブなシートを取得)
  const mySheet = SpreadsheetApp.getActiveSpreadsheet().insertSheet();;

  // ログに表示
  for(let i = 0; i < results.items.length; i++){
    Logger.log(results.items[i].snippet.title)

    // 追加(スプレッドシートにデータを表示)
    mySheet.getRange(i+1, 1).setValue(results.items[i].snippet.title)
    mySheet.getRange(i+1, 2).setValue(results.items[i].snippet.publishedAt)
    mySheet.getRange(i+1, 3).setValue(results.items[i].snippet.thumbnails.default.url)
    mySheet.getRange(i+1, 4).setValue(results.items[i].snippet.description)
    mySheet.getRange(i+1, 5).setValue(results.items[i].snippet.channelTitle)

  }
}

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny

タイトルとURLをコピーしました