Google apps script 谷歌应用程序脚本,如何将记录的数据发送到电子表格?
这可能不是很复杂,但我一直很难弄清楚,所以任何帮助都将是伟大的,谢谢 代码来自GoogleApps脚本示例脚本,我只是尝试对其进行一些更改,以便将数据发送到活动的电子表格中Google apps script 谷歌应用程序脚本,如何将记录的数据发送到电子表格?,google-apps-script,google-sheets,youtube-api,Google Apps Script,Google Sheets,Youtube Api,这可能不是很复杂,但我一直很难弄清楚,所以任何帮助都将是伟大的,谢谢 代码来自GoogleApps脚本示例脚本,我只是尝试对其进行一些更改,以便将数据发送到活动的电子表格中 function retrieveMyUploads() { var results = YouTube.Channels.list('contentDetails', {mine: true}); for(var i in results.items) { var item = results.items[
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;
}
}
}
函数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
我相信你的目标如下
- 您希望将脚本中的
的值放入电子表格playlitem.snippet.resourceId.videoId、playlitem.snippet.title
function retrieveMyUploads() {
var values = []; // <--- Added
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];
values.push([playlistItem.snippet.resourceId.videoId, playlistItem.snippet.title]); // <--- Added
Logger.log('[%s] Title: %s',
playlistItem.snippet.resourceId.videoId,
playlistItem.snippet.title);
}
nextPageToken = playlistResponse.nextPageToken;
}
}
var sheet = SpreadsheetApp.getActiveSheet(); // <--- Added
sheet.getRange(1, 1, values.length, values[0].length).setValues(values); // <--- Added
}
函数retrieveMyUploads(){
var values=[];//我相信您的目标如下
- 您希望将脚本中的
playlitem.snippet.resourceId.videoId、playlitem.snippet.title
的值放入电子表格
在本例中,如何准备一个数组并将值放入数组,然后将数组放入电子表格?当这反映到脚本中时,它将变成如下
修改脚本:
在这种情况下,请将以下脚本复制并粘贴到电子表格的脚本编辑器中。通过此操作,将值放入活动工作表中
function retrieveMyUploads() {
var values = []; // <--- Added
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];
values.push([playlistItem.snippet.resourceId.videoId, playlistItem.snippet.title]); // <--- Added
Logger.log('[%s] Title: %s',
playlistItem.snippet.resourceId.videoId,
playlistItem.snippet.title);
}
nextPageToken = playlistResponse.nextPageToken;
}
}
var sheet = SpreadsheetApp.getActiveSheet(); // <--- Added
sheet.getRange(1, 1, values.length, values[0].length).setValues(values); // <--- Added
}
函数retrieveMyUploads(){
var值=[]//