
Google ドライブ: フォルダ作成
この工程は、Google ドライブ の指定フォルダ内に新しいフォルダを作成します。
Basic Configs
- 工程名
- メモ
Configs for this Auto Step
- UserID
- C1: Google ドライブ に接続するユーザ(要アプリ管理権限) *
- ParentFolderId
- C2: 作成するフォルダの親フォルダの ID (空白の場合マイドライブのルートに作成されます)#{EL}
- FolderName
- C3: 作成するフォルダの名称 *#{EL}
- FolderIdItem
- C4: 作成したフォルダの ID を保存するデータ項目
- WebViewUrlItem
- C5: 作成したフォルダの表示 URL を保存するデータ項目
Notes
- C1 のユーザは、[アカウント設定]>[Google 連携]にて、Google ドライブと連携済みである必要があります
- ワークフロー基盤にて、Google 連携設定([システム設定]>[Google 連携])が必要です(要[システム管理権限])
Capture

See also
Script (click to open)
- 次のスクリプトが記述されている XML ファイルをダウンロードできます
- google-drive-folder-create.xml (C) Questetra, Inc. (MIT License)
- Professional のワークフロー基盤では、ファイル内容を改変しオリジナルのアドオン自動工程として活用できます
main();
function main() {
let parentFolderId = configs.get("ParentFolderId");
const folderName = configs.get("FolderName");
if (folderName === "" || folderName === null) {
throw "Folder Name is blank";
}
const quser = configs.getObject("UserID");
checkUser(quser);
const json = createFolder(quser, parentFolderId, folderName);
setData("FolderIdItem", json, "id");
setData("WebViewUrlItem", json, "webViewLink");
}
/**
* ユーザーIDをチェックする
* @param {QuserView} quser ユーザ
*/
function checkUser(quser) {
if (quser === null) {
throw "User not found";
}
}
/**
* プロセスにデータを保存する
* @param {String} configName 保存先データ項目の config 名
* @param {Object} json 保存するデータをメンバに持つ JSON オブジェクト
* @param {String} property 保存するデータのプロパティ名
*/
function setData(configName, json, property) {
const item = configs.get(configName);
if (item === null || item === "") {
return;
}
const data = json[property];
engine.setDataByNumber(item, data);
}
/**
* Google ドライブにフォルダを作成する
* @param {QuserView} quser ユーザ
* @param {String} parentFolderId 親フォルダのID
* @param {String} name フォルダ名
* @return {Object} jsonRes レスポンス本文の JSON オブジェクト
*/
function createFolder(quser, parentFolderId, name) {
let reqBody = {};
//mime type of google drive folder
reqBody["mimeType"] = "application/vnd.google-apps.folder";
if (parentFolderId !== "" && parentFolderId !== null) {
reqBody["parents"] = [parentFolderId];
}
reqBody["name"] = name;
const url = "https://www.googleapis.com/drive/v3/files/";
const response = httpClient
.begin()
.googleOAuth2(quser, "Drive")
.queryParam("fields", "id, webViewLink")
.queryParam("supportsAllDrives", "true")
.body(JSON.stringify(reqBody), "application/json; charset=UTF-8")
.post(url);
const status = response.getStatusCode();
const responseTxt = response.getResponseAsString();
if (status >= 300) {
const error = `Failed to create. status:${status}`;
engine.log(responseTxt);
throw error;
}
const jsonRes = JSON.parse(responseTxt);
return jsonRes;
}