forked from youtube/api-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add file for coming-soon Apps Script quickstart guide.
- Loading branch information
1 parent
954f7e0
commit 875d380
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(); | ||
} |