Last active
February 18, 2017 11:57
-
-
Save yyoshiki41/c7b5b839f1ab8872c52c1c7641b90910 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| var API_KEY = ''; | |
| var VIDEO_ID = ''; | |
| function trigger() { | |
| getStats(); | |
| } | |
| function getStats() { | |
| url = 'https://www.googleapis.com/youtube/v3/videos?id=' + VIDEO_ID + '&key=' + API_KEY + '&fields=items(statistics)&part=statistics' | |
| var response = UrlFetchApp.fetch(url); | |
| if (response.getResponseCode() != 200) { | |
| Logger.log("Error %s:", response); | |
| return; | |
| } | |
| var json = JSON.parse(response.getContentText()); | |
| var stats = json['items'][0]['statistics']; | |
| as = SpreadsheetApp.getActiveSheet(); | |
| lastRow = as.getLastRow(); | |
| cell = as.getRange('A1'); | |
| var d = new Date(); | |
| now = Utilities.formatDate(d, 'JST', 'M/d HH:mm'); | |
| cell.offset(lastRow, 0).setValue(now); | |
| cell.offset(lastRow, 1).setValue(stats['viewCount']); | |
| cell.offset(lastRow, 2).setValue(stats['likeCount']); | |
| cell.offset(lastRow, 3).setValue(stats['dislikeCount']); | |
| cell.offset(lastRow, 4).setValue(stats['favoriteCount']); | |
| cell.offset(lastRow, 5).setValue(stats['commentCount']); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment