我是 Apps 腳本的新手,我正在嘗試制作一個腳本來查找所有空檔案夾并更改它們的顏色。我設法做到了,當我在我的驅動器中嘗試它時,它運行良好,但是當我嘗試在共享驅動器中運行它時,它給了我這個錯誤:
Exception: Request failed for https://www.googleapis.com returned code 404. Truncated server response: {
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "File not found: 166gK63I72FZvqY0XjSE63z4SyQuSgGp... (use muteHttpExceptions option to examine full response)
我搜索了一些解決方案,唯一的一個是在 Google Cloud Platform 中創建一個專案。我這樣做了,并將我的腳本鏈接到 GCP 中的專案,但它給出了同樣的錯誤。基本上,我希望我的腳本能夠訪問我的共享驅動器。Shared Drive 很大,里面有很多檔案夾和檔案,不知道是不是api呼叫太多,還是權限問題。我希望有人能幫幫忙!非常感謝!我把我的腳本留在這里:
function findEmptyFolders() {
var parentFolder = DriveApp.getFolderById('Shared Drive ID');
var folders = parentFolder.getFolders();
while (folders.hasNext()) {
var childfolder = folders.next();
recurseFolder(parentFolder, childfolder);
}
}
function recurseFolder(parentFolder, folder) {
var filecount = 0;
var foldercount = 0;
var files = folder.getFiles();
var childfolders = folder.getFolders();
while (childfolders.hasNext()) {
var childfolder = childfolders.next();
recurseFolder(folder, childfolder);
foldercount ;
}
while (files.hasNext()) {
var file = files.next();
filecount ;
}
if (filecount == 0 && foldercount == 0) {
var id = folder.getId();
Logger.log(folderColor.setColorByName(id,'Yellow cab'));
}
}
var folderColor = {};
folderColor.setColorByName = function(id,name){
if(!colorPalette[name]){
throw "Name is not valid, please check name in colorPalette.";
}
this.setColor(id,colorPalette[name]);
return true;
}
folderColor.init = function(){
return this;
}
folderColor.setColor = function(id,hexa){
var url = 'https://www.googleapis.com/drive/v2/files/' id '?fields=folderColorRgb';
var param = {
method : "patch",
contentType: 'application/json',
headers : {"Authorization": "Bearer " ScriptApp.getOAuthToken()},
payload: JSON.stringify({folderColorRgb:hexa})
};
var html = UrlFetchApp.fetch(url,param).getContentText();
return html;
}
var colorPalette = {
"Chocolate ice cream":"#ac725e",
"Old brick red":"#d06b64",
"Cardinal":"#f83a22",
"Wild straberries":"#fa573c",
"Mars orange":"#ff7537",
"Yellow cab":"#ffad46",
"Spearmint":"#42d692",
"Vern fern":"#16a765",
"Asparagus":"#7bd148",
"Slime green":"#b3dc6c",
"Desert sand":"#fbe983",
"Macaroni":"#fad165",
"Sea foam":"#92e1c0",
"Pool":"#9fe1e7",
"Denim":"#9fc6e7",
"Rainy sky":"#4986e7",
"Blue velvet":"#9a9cff",
"Purple dino":"#b99aff",
"Mouse":"#8f8f8f",
"Mountain grey":"#cabdbf",
"Earthworm":"#cca6ac",
"Bubble gum":"#f691b2",
"Purple rain":"#cd74e6",
"Toy eggplant":"#a47ae2"
};
uj5u.com熱心網友回復:
在您的腳本中,如何進行以下修改?
從:
var url = 'https://www.googleapis.com/drive/v2/files/' id '?fields=folderColorRgb';
到:
var url = 'https://www.googleapis.com/drive/v2/files/' id '?fields=folderColorRgb&supportsAllDrives=true';
參考:
- 檔案:補丁
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/449463.html
