Last active
November 13, 2021 03:24
-
-
Save senyaitiya/044c2d2c855646db38c4928418891204 to your computer and use it in GitHub Desktop.
GASとYoutubeAPIで再生リスト内の動画情報を取得
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function PlayList() { | |
//シート定義 | |
const ss = SpreadsheetApp.getActiveSpreadsheet() | |
const sheetName1 = "シート1"; | |
const srcSheet = ss.getSheetByName(sheetName1); | |
//データを貼り付けるシートをクリア | |
srcSheet.clear() | |
//APIキー | |
const key = "{YoutubeAPIキー}"; | |
//再生リストID定義位置 | |
const playlistID = "{再生リストID}"; | |
//APIキーの呼び出し | |
const dataURL = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=49&playlistId=" + playlistID + "&key=" + key; | |
//レスポンス値にjson形式で挿入 | |
const response = JSON.parse(UrlFetchApp.fetch(dataURL).getContentText()); | |
//JSON分解 | |
response.items.forEach((item, i) => { | |
//投稿日付 | |
const publishedAt = item.snippet.publishedAt; | |
//動画タイトル | |
const title = item.snippet.title; | |
//動画説明 | |
const description = item.snippet.description; | |
//動画ID | |
const videoId = item.snippet.resourceId.videoId; | |
srcSheet.getRange(i + 1, 1).setValue(publishedAt); | |
srcSheet.getRange(i + 1, 2).setValue(title); | |
srcSheet.getRange(i + 1, 3).setValue(description); | |
if(videoId) { | |
srcSheet.getRange(i + 1, 4).setFormula('=HYPERLINK("https://www.youtube.com/watch?v=' + videoId + '")') | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ご返信ありがとうございます(^^)