我想从Google表格上的频道ID收集Youtube频道信息。
目前,我正在使用下面的代码按频道名称收集频道信息...,效果很好。
我现在想要的是添加另一个选项,通过输入频道ID而不是频道名称来收集相同的信息。
任何想法我必须在此处更改/添加的内容
代码示例:
// 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.snippet.title, channel.id,
channel.statistics.viewCount, channel.statistics.subscriberCount,];
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 onOpen() {
var firstCell = SpreadsheetApp.getActiveSheet().getRange(1, 1).getValue();
if (firstCell != 'Title') {
var headerRow = ["Title", "ID", "View counts"];
SpreadsheetApp.getActiveSpreadsheet().appendRow(headerRow);
}
var ui = SpreadsheetApp.getUi();
ui.createMenu('YouTube Data')
.addItem('Add channel name', 'getChannel')
.addToUi();
}