Google apps script 我可以使用谷歌应用程序脚本获取YouTube视频标签吗?
我想在新的YouTube视频发布后发送一封电子邮件。我需要以某种方式选择什么视频将触发电子邮件。我想我会用标签。但是我怎样才能访问标签呢 我用这个来列出我所有的视频。它工作得很好,但我不知道如何访问标签。从我在SO和Google上所做的搜索来看,在我看来,使用Google应用程序脚本是不可能的,但文档上说,Google apps script 我可以使用谷歌应用程序脚本获取YouTube视频标签吗?,google-apps-script,youtube-data-api,Google Apps Script,Youtube Data Api,我想在新的YouTube视频发布后发送一封电子邮件。我需要以某种方式选择什么视频将触发电子邮件。我想我会用标签。但是我怎样才能访问标签呢 我用这个来列出我所有的视频。它工作得很好,但我不知道如何访问标签。从我在SO和Google上所做的搜索来看,在我看来,使用Google应用程序脚本是不可能的,但文档上说,。。。例如,在播放列表资源中,snippet属性包含诸如author、title、description、**TAGS**和timeCreated等属性。因此,如果设置part=snippet
。。。例如,在播放列表资源中,snippet属性包含诸如author、title、description、**TAGS**和timeCreated等属性。因此,如果设置part=snippet,API响应将包含所有这些属性…
所以看起来我可以得到视频的标签。有人能帮我吗
我想要的是如图所示的标签my_标签
函数retrieveMyUploads(){
var results=YouTube.Channels.list('contentDetails',{mine:true});
对于(results.items中的var i){
var项目=结果。项目[i];
//获取嵌套在contentDetails中的播放列表ID,如中所述
//频道资源:https://developers.google.com/youtube/v3/docs/channels
var playlaid=item.contentDetails.relatedPlaylists.uploads;
var nextPageToken='';
//此循环检索一组播放列表项,并检查
//响应以确定列表是否包含其他项。它重复该过程
//直到它检索到列表中的所有项。
while(nextPageToken!=null){
var playlayresponse=YouTube.playlitems.list('snippet'{
playlid:playlid,
最大结果:25,
pageToken:nextPageToken
});
对于(var j=0;j
修改点:
- 当我看到“播放项目”的官方文件时,我找不到“标签”。因此,在本例中,作为一种解决方法,我建议使用“Videos:list”方法来检索标记
- 当我看到“播放项目”的官方文件时,我找不到“标签”。因此,在本例中,作为一种解决方法,我建议使用“Videos:list”方法来检索标记
YouTube.playlitems.list
结果是按publishedAt排序的?“如何找到答案?”Radek感谢您的回复。我很高兴你的问题解决了。关于您的附加问题,很遗憾,我找不到用于排序结果值的API参数。我为此道歉。这样,在当前阶段,当您想要对结果值进行排序时,需要在检索值后使用脚本对值进行排序。对于这种情况,我深表歉意。@Radek:事实上,playlitems.list
端点在查询时将videoPublishedAt
参数设置为频道上载播放列表的ID,返回按videoPublishedAt
排序的结果集。端点的此属性没有这样的文档记录,但请查看。@stvar谢谢您提供的其他信息。而且,我为我的拙劣技能深表歉意。非常有效,谢谢。我不明白为什么这个url会有“标签”,但这一个不知道你是否知道YouTube.playlitems.list
结果是按publishedAt排序的?“如何找到答案?”Radek感谢您的回复。我很高兴你的问题解决了。关于您的附加问题,很遗憾,我找不到用于排序结果值的API参数。我为此道歉。这样,在当前阶段,当您想要对结果值进行排序时,需要在检索值后使用脚本对值进行排序。对于这种情况,我深表歉意。@Radek:事实上,playlitems.list
端点在查询时将videoPublishedAt
参数设置为频道上载播放列表的ID,返回按videoPublishedAt
排序的结果集。端点的此属性没有这样的文档记录,但请查看。@stvar谢谢您提供的其他信息。而且,我为我的拙劣技能深表歉意。
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;
}
}
}
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);
}
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);
// I added below script.
var res = YouTube.Videos.list('snippet', {id: playlistItem.snippet.resourceId.videoId});
var tagList = res.items.map(e => ({id: e.id, tags: e.snippet.tags}));
Logger.log(tagList)
}
function myFcuntion() {
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.
var videoIds = []; // Added
while (nextPageToken != null) {
var playlistResponse = YouTube.PlaylistItems.list('snippet', {
playlistId: playlistId,
maxResults: 25,
pageToken: nextPageToken,
fields: "items"
});
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);
videoIds.push(playlistItem.snippet.resourceId.videoId); // Added
}
nextPageToken = playlistResponse.nextPageToken;
}
// I added below script.
var requests = {
batchPath: "batch/youtube/v3",
requests: videoIds.map(id => ({
method: "GET",
endpoint: `https://www.googleapis.com/youtube/v3/videos?part=snippet&id=${id}`,
})),
accessToken: ScriptApp.getOAuthToken(),
};
var result = BatchRequest.EDo(requests); // Using GAS library
var tagList = result.flatMap(({items}, i) => items.map(({snippet}) => ({id: videoIds[i], tags: snippet.tags})));
Logger.log(tagList);
}
}