Gists

In this post, I would like to introduce 2 sample scripts for copying and deleting the dimension groups in Google Spreadsheet using Google Apps Script.
Unfortunately, in the current stage, all dimension groups cannot be copied by one action, and also, all dimension groups cannot be deleted by one action. In this post, these can be achieved using Google Apps Script.
These sample scripts use Sheets API. So, please enable Sheets API at Advanced Google services.
Gists
This report is a workaround for reflecting the latest Google Apps Script to the deployed Web Apps without redeploying.
Pattern 1
Of course, when the developer mode of https://script.google.com/macros/s/###/dev is used, the latest script can be used without redeploying.
But, in this case, only the permitted users can use it using the access token. when you want to achieve this using the endpoint of https://script.google.com/macros/s/###/exec without the access token, in order to reflect the latest script to Web Apps, it is required to redeploy. As another pattern, I would like to introduce a workaround for this situation.
Gists
This is a sample script for searching Gmail messages by Gmail Filters using Google Apps Script.
At Gmail, users can set the filter for the Emails. With this filter, users can filter the Emails of Gmail. But, when the users want to search by the installed filter using Google Apps Script, unfortunately, it seems that this cannot be directly achieved. For example, messages cannot be searched using a filter ID.
Gists
These are sample scripts for retrieving specific folders from Google Drive using Google Drive service (DriveApp) with Google Apps Script.
Retrieving folders in own Google Drive
const folders = DriveApp.searchFolders(
`'${Session.getActiveUser().getEmail()}' in owners and trashed=false`
);
const res = [];
while (folders.hasNext()) {
const folder = folders.next();
res.push(folder.getName());
}
console.log(res);
Retrieving folders in shared Drives
const folders = DriveApp.searchFolders(
`not '${Session.getActiveUser().getEmail()}' in owners and trashed=false`
);
const res = [];
while (folders.hasNext()) {
const folder = folders.next();
const owner = folder.getOwner();
if (owner === null) {
res.push(folder.getName());
}
}
console.log(res);
Retrieving folders of sharedWithMe
const folders = DriveApp.searchFolders(`sharedWithMe`);
const res = [];
while (folders.hasNext()) {
const folder = folders.next();
res.push(folder.getName());
}
console.log(res);
Gists

This is a workaround for converting a Gmail message to a PNG image using Google Apps Script.
Sample script
Please set the message ID of Gmail.
function myFunction() {
var id = "###"; // Please set your message ID of Gmail.
var message = GmailApp.getMessageById(id);
var date = Utilities.formatDate(
message.getDate(),
Session.getScriptTimeZone(),
"yyyy-MM-dd HH:mm:ss"
);
var from = message.getFrom();
var to = message.getTo();
var subject = message.getSubject();
var htmlBody = message.getBody();
var imageBlob = Charts.newTableChart()
.setDataTable(
Charts.newDataTable()
.addColumn(Charts.ColumnType.STRING, "")
.addRow([`<p style="font-size: 120%">Date: ${date}</p>`])
.addRow([`<p style="font-size: 120%">From: ${from}</p>`])
.addRow([`<p style="font-size: 120%">To: ${to}</p>`])
.addRow([`<p style="font-size: 120%">Subject: ${subject}</p>`])
.addRow([htmlBody])
.build()
)
.setOption("allowHtml", true)
.setDimensions(512, 512)
.build()
.getBlob();
DriveApp.createFile(imageBlob.setName("sample.png"));
}

My report has been featured by Google Workspace Developer Newsletter. Ref
The featured report is “Report: Implementing Pseudo 2FA for Web Apps using Google Apps Script”.
Gists

This is a simple sample script for uploading a video file on Google Drive to YouTube with the resumable upload using Google Apps Script.
When you want to upload a video file to YouTube using Google Apps Script, when YouTube API of Advanced Google services is used, the maximum file size is 5 MB, because, in this case, the video file is uploaded with multipart/form-data. When you want to use a video file with more file size using Google Apps Script, a resumable upload is required to be used. But, unfortunately, in the current stage, the methods of Google Apps Script for uploading large video files are not prepared. And also, when I saw the document of resumable upload on YouTube in the official document, I thought that it might be a bit complicated for understanding the resumable upload process. Ref So, in this post, I would like to introduce a simple sample script for uploading video data of more than 5 MB with the resumable upload using Google Apps Script. In this case, the video file is existing in Google Drive. The video file on Google Drive is uploaded to YouTube using Google Apps Script. When this sample script will help you understand the resumable upload of YouTube, I’m glad.
Gists
This is a sample curl command for uploading a video file to YouTube with the resumable upload using YouTube API.
In order to upload a video file to YouTube with the resumable upload using YouTube API, the following 2 processes are required to be done. The basic process of the resumable upload for YouTube is the same with Drive API. Ref So, I think that this document of Drive API might be useful for understanding the resumable upload process.
Gists
This is a workaround for detecting to edit Google Spreadsheet using Sheets API with the service account.
It has already been found that when Google Spreadsheet is edited using Sheets API, this can be detected by the installed OnChange trigger. For example, when a Spreadsheet is edited using Sheets API with the access token retrieved from your Google account, the event object of the installable OnChange trigger includes your email address and nickname. With this information, you can know the user who edited the Spreadsheet. However, when the Spreadsheet is edited using Sheets API with the access token retrieved from the service account, unfortunately, the email of the service account is not included in the event object of the OnChange event. It is considered that this is the current specification.
Gists

These are the sample scripts for using getBatchGet, batchUpdateContacts, batchDeleteContacts, batchCreateContacts of People API with Google Apps Script.
When the data is retrieved and put with People API, the process cost can be reduced by using batch requests. Fortunately, in the current stage, People API has native methods for using batch requests. Those are getBatchGet, batchCreateContacts, batchDeleteContacts, and batchUpdateContacts. In this post, I would like to introduce the sample scripts for using the batch requests of People API.