youtube - 如何从 Google 表格上的频道 ID 获取 Youtube 频道信息?
问题描述
我想从 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();
}
解决方案
推荐阅读
- json - jsonschema:对象数组中的唯一属性
- android - 我的应用程序反复请求权限,尽管用户授予了它
- ios - 集合视图中不同部分的不同布局
- ruby-on-rails - Rails 5控制器中的范围嵌套关联
- r - R - rlm - R 中稳健回归后的 p 值和 R 平方
- react-native - React-native-document-picker 在 android 中不起作用
- php - 高级自定义字段专业转发器,使用引导滑块
- mongodb - MongoDB - 在记录属性中查找重复的元素
- android - 升级到支持 AndroidX 的 Nativescript 6 后,谷歌地图在 Android 中停止工作
- docker - 如何在 docker 中构建 go 模块?