问题:如何在Google Apps脚本中使用delete个playlistItem?
我尝试了什么:
Missing name after . operator. (line 123, file "Code")
错误(我感觉它可能与JavaScript delete运算符有关,但不确定。): YouTube.PlaylistItems.delete()
YouTube.PlaylistItems.delete("PLi22jkbHFzDjQNWcy4qfLamNjyb0nvkq8")
YouTube.PlaylistItems.delete({id: "PLi22jkbHFzDjQNWcy4qfLamNjyb0nvkq8"})
var payload = { "id" : "PLi22jkbHFzDjQNWcy4qfLamNjyb0nvkq8", }; var options = { "method" : "delete", "payload" : payload }; Logger.log(UrlFetchApp.fetch("https://www.googleapis.com/youtube/v3/playlistItems", options));
非常感谢任何帮助。
额外的详细信息。我想要做的是清除播放列表中的所有项目,我已经拥有以下代码:
var result = YouTube.PlaylistItems.list('id', {
playlistId: "2L1YG9ktx9sVdo-PMFD2iwCC-UWmkYrgQ-"
});
Logger.log(result.items.length);
var items = result.items;
for (var i = 0; i < items.length; i++) {
Logger.log(items[i].id);
// Deletion of the item with id of "items[i].id is expected to happen here
}
答案 0 :(得分:1)
我认为在Apps脚本中不是delete()。请尝试使用YouTube.PlaylistItems.remove(id)
。我尝试在我的脚本中添加此方法,并在下拉列表中自动填充remove方法。没有删除方法。
希望有所帮助!
答案 1 :(得分:1)
您没有使用videoId,您使用playlistItem的ID ...
while (nextPageToken != null) {
var playlistResponse = YouTube.PlaylistItems.list('snippet', {playlistId: playlistId, maxResults: 50,pageToken: nextPageToken});
for (var j = 0; j < playlistResponse.items.length; j++) {
var playlistItem = playlistResponse.items[j];
playlistItemsDelete(playlistItem.id)
//Logger.log('[%s] Title: %s', playlistItem.snippet.resourceId.videoId, playlistItem.snippet.title);
}
......然后......
function playlistItemsDelete(id){ // var params = {&#39; onBehalfOfContentOwner&#39;:&#39; everythingability&#39;}; //查看函数的完整示例
YouTube.PlaylistItems.remove(ID)
}