'how to trash files in Google Photos via Appscript?
I wrote the attached script to read a json formatted text file, and trash listed files in my google drive. I want to do the same for files in Google Photos, but a I can't see a way to access them from Appscript. I am fairly new to this. Would anyone have tips on accessing Google Photos via Appscript?
function trashFilesInList(){
var count = 0;
var errCount = 0;
var filesjson = JSON.parse(importTextFromDrive());
for (var i = 0; i < filesjson.length; i++) {
var filename = filesjson[i].title;
try{
var file = getFileFromName(filename);
if (file !== ""){
file.setTrashed(true);
count++;
}
}
catch(err){
errCount++;
}
}
Browser.msgBox(count + " files trashed. " + errCount + " errors.")
}
function getFileFromName(fileName){
try{
var files = findFilesInDrive(fileName);
if(files.length === 0) {
return "";
} else if(files.length > 1) {
return "";
}
var file = files[0];
return file;
}
catch(err){
return ""
}
}
function importTextFromDrive() {
var fileName = "PhotosDeleteList.txt";
var files = findFilesInDrive(fileName);
if(files.length === 0) {
displayToastAlert("No files with name \"" + fileName + "\" were found in Google Drive.");
return;
} else if(files.length > 1) {
displayToastAlert("Multiple files with name " + fileName +" were found. This program does not support picking the right file yet.");
return;
}
var file = files[0];
var contents = file.getBlob().getDataAsString();
return contents;
}
//Returns files in Google Drive that have a certain name.
function findFilesInDrive(filename) {
var files = DriveApp.getFilesByName(filename);
var result = [];
while(files.hasNext())
result.push(files.next());
return result;
}
//Displays an alert as a Toast message
function displayToastAlert(message) {
SpreadsheetApp.getActive().toast(message, "⚠️ Alert");
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
