Skip to content

Commit 875d380

Browse files
Add file for coming-soon Apps Script quickstart guide.
1 parent 954f7e0 commit 875d380

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

apps-script/quickstart.gs

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

0 commit comments

Comments
 (0)