我想要谷歌应用程序脚本,它应该读取完成的谷歌任务并将它们作为一行添加到谷歌电子表格中。任何人都可以帮助我
1 回答
0
阅读更多https://developers.google.com/apps-script/advanced/tasks
是否需要应用可选参数 showHidden = true 才能完成任务。
在脚本编辑器中打开菜单资源 - 高级 Google 服务并打开“任务 API”。然后试试这段代码:
function myFunction() {
getCompletedTasks(getTaskListByTitle('ToDo'));
}
function getTaskListByTitle(titleTasksList) {
if (typeof titleTasksList === 'undefined') { titleTasksList = 'default'; }
var rezultId = 0;
var response = Tasks.Tasklists.list();
var taskLists = response.items;
if (taskLists && taskLists.length > 0) {
for (var i = 0; i < taskLists.length; i++) {
var taskList = taskLists[i];
if (titleTasksList == 'default') {
rezultId = taskList.id; //return first item
break;
} else {
//Logger.log('%s (%s)', taskList.title, taskList.id);
if (titleTasksList == taskList.title) {
rezultId = taskList.id;
break;
}
}
}
} else {
Logger.log('No task lists found.');
}
return rezultId;
}
function getCompletedTasks(taskListId) {
var optionalArgs = {
maxResults: 100,
showHidden: true
};
var tasks = Tasks.Tasks.list(taskListId, optionalArgs);
var SPREADSHEET = SpreadsheetApp.getActiveSpreadsheet();
var rngStartReport = SPREADSHEET.getRange('A1');
var k = 0;
if (tasks.items) {
for (var i = 0; i < tasks.items.length; i++) {
var task = tasks.items[i];
rngStartReport.offset(k, 0).setValue(task.title);
rngStartReport.offset(k, 1).setValue(task.status);
k++;
Logger.log('Task with title "%s" and ID "%s" was found.',
task.title, task.id);
}
} else {
Logger.log('No tasks found.');
}
}
于 2019-02-09T19:04:11.130 回答