【发布时间】:2021-05-14 18:14:42
【问题描述】:
我想在新的 YouTube 视频发布后发送电子邮件。我需要以某种方式选择将触发电子邮件的视频。我以为我会使用标签。但是如何访问标签呢?
我正在使用这个sample script 来列出我的所有视频。它运作良好,但我不知道如何访问标签。从我在 SO 和 Google 上所做的搜索来看,在我看来,使用 Google Application Script 是不可能的,但文档 PlaylistItems 说 ... For example, in a playlist resource, the snippet property contains properties like author, title, description, **TAGS**, and timeCreated. As such, if you set part=snippet, the API response will contain all of those properties...
所以看起来我可以获取视频的标签。有人可以帮我怎么做吗?
function retrieveMyUploads() {
var results = YouTube.Channels.list('contentDetails', {mine: true});
for(var i in results.items) {
var item = results.items[i];
// Get the playlist ID, which is nested in contentDetails, as described in the
// Channel resource: https://developers.google.com/youtube/v3/docs/channels
var playlistId = item.contentDetails.relatedPlaylists.uploads;
var nextPageToken = '';
// This loop retrieves a set of playlist items and checks the nextPageToken in the
// response to determine whether the list contains additional items. It repeats that process
// until it has retrieved all of the items in the list.
while (nextPageToken != null) {
var playlistResponse = YouTube.PlaylistItems.list('snippet', {
playlistId: playlistId,
maxResults: 25,
pageToken: nextPageToken
});
for (var j = 0; j < playlistResponse.items.length; j++) {
var playlistItem = playlistResponse.items[j];
Logger.log('[%s] Title: %s',
playlistItem.snippet.resourceId.videoId,
playlistItem.snippet.title);
}
nextPageToken = playlistResponse.nextPageToken;
}
}
}
【问题讨论】:
-
我无法理解您当前的脚本和您的目标之间的关系。我为此道歉。可以问一下具体情况吗?
-
脚本列出了我所有的视频,特别是视频 ID 和标题。我也想得到那个标签。
-
我更新了我的问题并添加了我想要的图片。
-
感谢您的回复。根据您的回复,我提出了一个修改后的脚本作为答案。你能确认一下吗?如果这不是您期望的方向,我深表歉意。
标签: google-apps-script youtube-data-api