在Google Apps脚本中列出Youtube频道的所有视频 [英] List all videos of a Youtube channel in Google Apps Script

查看:130
本文介绍了在Google Apps脚本中列出Youtube频道的所有视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Youtube Data API 列出了Google电子表格中前25个频道的视频标题和ID,但由于某些原因,我只能获得Title这个频道。这里是我的代码,

 函数searchByChannel(){
var results = YouTube.Channels.list('id, snippet',{
id:'UC-9-kyTW8ZkZNDHQJ6FgpwQ',
maxResults:25
});

var title =;
var id =;
var lr = 0;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet1 = ss.getSheetByName(Sheet1);
for(var i = 0; i< results.items.length; i ++){
var item = results.items [i];
title = item.snippet.title;
id = item.id.videoId;
lr = sheet1.getLastRow()+ 1;
sheet1.getRange(lr,1).setValue(title);
sheet1.getRange(lr,2).setValue(id);
lr ++;
}
}

我是新来的YouTube数据API,不知道我在这里做错了什么。如何使用Google Apps脚本在电子表格中列出25个视频ID和标题?严重需要这个帮助!感谢。

解决方案

YouTube.Channels 的文档声明将返回关于该频道的信息,而不是视频,这就是为什么您获得该频道的信息。



YouTube.Search 另一方面收集有关视频的信息,并且您可以为它提供一个 channelId 参数,以便查找指定的频道,因此您的结果代码应如下所示:

  var results = YouTube.Search.list('id,snippet',{
channelId:'UC-9- kyTW8ZkZNDHQJ6FgpwQ',
maxResults:25
});


I'm using Youtube Data API to list first 25 video titles and ids of a channel in google spreadsheet, but for some reason I'm only getting the Title of the channel. Here are my codes,

function searchByChannel() {
    var results = YouTube.Channels.list('id,snippet', {
        id: 'UC-9-kyTW8ZkZNDHQJ6FgpwQ',
        maxResults: 25
    });

    var title = "";
    var id = "";
    var lr = 0;
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet1 = ss.getSheetByName("Sheet1");
    for (var i = 0; i < results.items.length; i++) {
        var item = results.items[i];
        title = item.snippet.title;
        id = item.id.videoId;
        lr = sheet1.getLastRow() + 1;
        sheet1.getRange(lr, 1).setValue(title);
        sheet1.getRange(lr, 2).setValue(id);
        lr++;
    }
}

I'm new to youtube data api so I don't know what I'm doing wrong here. How can I list 25 video ids and titles in my spreadsheet using google apps script? Need this help badly! Thanks.

解决方案

The documentation for the YouTube.Channels states that it will return information about the Channel, nothing about the videos, that's why your getting the channel's info.

YouTube.Search on the other hand gather info about videos, and you can feed it a channelId parameter that will seek into a specified channel, as such, your result code should look like:

  var results = YouTube.Search.list('id,snippet', {
    channelId:'UC-9-kyTW8ZkZNDHQJ6FgpwQ',
    maxResults: 25
  });

这篇关于在Google Apps脚本中列出Youtube频道的所有视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆