DriveAPITips

GAS Library - GASProjectApp

Overview This is a Google Apps Script library for creating, updating and exporting Google Apps Script project of the standalone type using Drive API. In this case, Apps Script API is not used. Description I had reported “Drive API cannot create Google Apps Script project no longer” before. Ref About this, I had reported the future request. Ref At July 30, 2020, I could confirm that the Google Apps Script project of the standalone type got to be able to be created by multipart/form-data using Drive API again.

Drive API got to be able to create Google Apps Script project again

Gists I have reported “Drive API cannot create Google Apps Script project no longer”. Ref About this, I had reported the future request. Ref Today, I could confirm that the Google Apps Script project of the standalone type got to be able to be created by multipart/form-data using Drive API. This is a good news for me. By this, the following 2 patterns can be used from now. Pattern 1: Create new standalone GAS project by Apps Script API.

Uploading Files of multipart/form-data to Google Drive using Drive API with Node.js

Gists These are the sample scripts for uploading files of multipart/form-data to Google Drive using Drive API with Node.js. In this case, googleapis for Node.js is not used. In these sample script, the maximum file size is 5 MB. Please be careful this. When you want to upload the files more than 5 MB, please check this report. Sample script 1 This sample script uploads a file using the modules of fs and request.

GAS Library - OwnershipTransfer

Overview This is a Google Apps Script library for achieving the ownership-transfer of the specific folder including the files and sub-folders using Drive API. IMPORTANT: PLEASE BE CAREFUL THIS. At first, please read this section I cannot take responsibility for the problems occurred by this library. So when you use this library, please use it by according to your own decision and at your own responsibility. This GAS library transfers the ownership of files and folders.

Specification of Files: copy in Drive API was changed

I noticed that the specification of Files: copy in Drive API was changed. About the method of Files: copy in Drive API v3, this method could be used with the scope of https://www.googleapis.com/auth/drive.readonly until July 5, 2020. But I confirmed that in the current stage, the scope is required to be changed to the following scopes. https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/drive.appdata https://www.googleapis.com/auth/drive.photos.readonly Please be careful this.

Creating Shortcut on Google Drive using Google Apps Script

Gists This is a sample script for creating a shortcut on Google Drive using Google Apps Script. Sample script Before you run the script, please enable Drive API at Advanced Google services. function createShortcut(targetId, name, folderId) { const resource = { shortcutDetails: { targetId: targetId }, title: name, mimeType: "application/vnd.google-apps.shortcut", }; if (folderId) resource.parents = [{ id: folderId }]; const shortcut = Drive.Files.insert(resource); return shortcut.id; } // Please run this function.

GAS Library - CopyFolder

Overview This is Google Apps Script library for copying folder on Google Drive. Description I have sometimes the situation that it is required to back up the folder on Google Drive to Google Drive. But unfortunately, the method of makeCopy() of Class File and the method of Files: copy of Drive API cannot be used for directly copying the folder on Google Drive. So I created this as a library. This library can copy the folder on Google Drive.

Updating a File with Resumable Upload using Drive API

Gists This is a sample flow for updating a file with the resumable upload using Drive API. Sample situation: In this answer, as a sample situation, it supposes that a text file in Google Drive is updated by the resumable upload with the multiple chunks. And as the method for requesting, I use the curl command. I prepared 2 files for 2 chunks. As the test situation, the 2 chunks of 262,144 bytes and 37,856 bytes are uploaded.

Retrieving Files and Folders without Parents in Google Drive

Gists This is a sample script for retrieving the files and folders which have no parents in own Google Drive. When you use this script, please enable Drive API at Advanced Google services. Sample script const myFunction = () => { const token = ScriptApp.getOAuthToken(); const fields = decodeURIComponent( "nextPageToken,files(name,id,mimeType,parents)" ); const q = decodeURIComponent("'me' in owners and trashed = false"); let files = []; let pageToken = ""; do { const res = UrlFetchApp.

Drive API cannot create Google Apps Script project no longer

Gists Today, I noticed that new Google Apps Script project of the standalone script type cannot be created by the method of Files: create in Drive API. From now, in order to manage the Google Apps Script project, only Google Apps Script API is required to be used. By this, the following issues are brought. When the new standalone GAS project is created in the specific folder by uploading the local script, the following flow is required to be run.

Moving File to Specific Folder using Google Apps Script

Gists These are 3 sample scripts for moving a file to the specific folder in Google Drive using Google Apps Script. Sample script 1 In this script, only Drive Service is used. var sourceFileId = "###"; var destinationFolderId = "###"; var file = DriveApp.getFileById(sourceFileId); DriveApp.getFolderById(destinationFolderId).addFile(file); file .getParents() .next() .removeFile(file); Sample script 2 In this script, only Drive API at Advanced Google services. (In this case, it's Drive API v2.) var sourceFileId = "###"; var destinationFolderId = "###"; Drive.

One Time Download for Google Drive

Overview This is a sample script for downloading files from Google Drive by the one time download method. Description When you download a file from Google Drive, in generally, the login and the access token are required. If you want to download the file without the authorization for the simple situation, the file is required to be publicly shared. But the file might not be able to be shared publicly, because of various reasons.

Uploading File to Shared Folder using ggsrun

Gists ggsrun is also a CLI application for using Google Drive. Here, I would like to introduce a sample command. This is a sample command for uploading a file to a shared folder using ggsrun. This situation supposes that the shared folder is https://drive.google.com/drive/folders/abcdefg?usp=sharing and the folder has the edit permission. Sample command: $ ggsrun u -f "sample.txt" -p "abcdefg" --serviceaccount "###JSON file of Service Account###" If you have already used OAuth2, you can upload the file by ggsrun u -f "sample.

(NEW) Retrieve old revision file from Google Drive

This method was updated at July 12, 2017. In order to use this, at first, please retrieve your access token and enable Drive API. 1. File ID Retrieve file id from file name. curl -X GET -sSL \ -H 'Authorization: Bearer ### Access token ###' \ 'https://www.googleapis.com/drive/v3/files?q=name="### FileName ###"&fields=files(id,name)' Reference : https://developers.google.com/drive/v3/reference/files/list 2. Revision ID Retrieve revision id from file id. curl -X GET -sSL \ -H 'Authorization: Bearer ### Access token ###' \ 'https://www.

Retrieve old revision file from Google Drive

I introduce 2 kinds of methods. One is to use curl. Another is to use wget. At this time, I could know that wget can be also used as same as curl. In order to use this, at first, please retrieve your access token and enable Drive API. 1. File ID Retrieve file id from file name. curl -X GET -sSL \ -H 'Authorization: Bearer ### Access token ###' \ 'https://www.