-
Notifications
You must be signed in to change notification settings - Fork 3k
/
quickstart.gs
36 lines (32 loc) · 1.27 KB
/
quickstart.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Note: Apps Script automatically requests authorization
// based on the API's used in the code.
function channelsListByUsername(part, params) {
var response = YouTube.Channels.list(part,
params);
var channel = response.items[0];
var dataRow = [channel.id, channel.snippet.title, channel.statistics.viewCount];
SpreadsheetApp.getActiveSpreadsheet().appendRow(dataRow);
}
function getChannel() {
var ui = SpreadsheetApp.getUi();
var channelName = ui.prompt("Enter the channel name: ").getResponseText();
channelsListByUsername('snippet,contentDetails,statistics',
{'forUsername': channelName});
}
function getGoogleDevelopersChannel() {
channelsListByUsername('snippet,contentDetails,statistics',
{'forUsername': 'GoogleDevelopers'});
}
function onOpen() {
var firstCell = SpreadsheetApp.getActiveSheet().getRange(1, 1).getValue();
if (firstCell != 'ID') {
var headerRow = ["ID", "Title", "View count"];
SpreadsheetApp.getActiveSpreadsheet().appendRow(headerRow);
}
var ui = SpreadsheetApp.getUi();
ui.createMenu('YouTube Data')
.addItem('Add channel data', 'getChannel')
.addSeparator()
.addItem('Add GoogleDevelopers data', 'getGoogleDevelopersChannel')
.addToUi();
}