ไฟล์ใน Google ไดรฟ์ คุณสามารถเข้าถึงหรือสร้างไฟล์จาก DriveApp
// Trash every untitled spreadsheet that hasn't been updated in a week. var files = DriveApp.getFilesByName('Untitled spreadsheet'); while (files.hasNext()) { var file = files.next(); if (new Date() - file.getLastUpdated() > 7 * 24 * 60 * 60 * 1000) { file.setTrashed(true); } }
วิธีการ
วิธีการ | ประเภทการแสดงผล | รายละเอียดแบบย่อ |
---|---|---|
addCommenter(emailAddress) | File | เพิ่มผู้ใช้ที่ต้องการลงในรายการผู้แสดงความคิดเห็นสําหรับ File |
addCommenter(user) | File | เพิ่มผู้ใช้ที่ต้องการลงในรายการผู้แสดงความคิดเห็นสําหรับ File |
addCommenters(emailAddresses) | File | เพิ่มอาร์เรย์ผู้ใช้ที่ระบุลงในรายการผู้แสดงความคิดเห็นสําหรับ File |
addEditor(emailAddress) | File | เพิ่มผู้ใช้ที่ต้องการลงในรายการเครื่องมือแก้ไขของ File |
addEditor(user) | File | เพิ่มผู้ใช้ที่ต้องการลงในรายการเครื่องมือแก้ไขของ File |
addEditors(emailAddresses) | File | เพิ่มอาร์เรย์ผู้ใช้ที่ระบุลงในรายการผู้แก้ไขสําหรับ File |
addViewer(emailAddress) | File | เพิ่มผู้ใช้ที่ต้องการลงในรายการผู้ชมสําหรับ File |
addViewer(user) | File | เพิ่มผู้ใช้ที่ต้องการลงในรายการผู้ชมสําหรับ File |
addViewers(emailAddresses) | File | เพิ่มอาร์เรย์ผู้ใช้ที่ระบุลงในรายการผู้ชมสําหรับ File |
getAccess(email) | Permission | ได้รับสิทธิ์ที่ผู้ใช้ดังกล่าวได้รับ |
getAccess(user) | Permission | ได้รับสิทธิ์ที่ผู้ใช้ดังกล่าวได้รับ |
getAs(contentType) | Blob | ส่งคืนข้อมูลภายในออบเจ็กต์นี้เป็น Blob ที่แปลงเป็นประเภทเนื้อหาที่ระบุ |
getBlob() | Blob | ส่งคืนข้อมูลภายในออบเจ็กต์นี้เป็น BLOB |
getDateCreated() | Date | ดูวันที่สร้าง File |
getDescription() | String | รับคําอธิบายสําหรับ File |
getDownloadUrl() | String | รับ URL ที่ใช้ดาวน์โหลดไฟล์ได้ |
getEditors() | User[] | รับรายชื่อผู้แก้ไขสําหรับ File นี้ |
getId() | String | รับรหัสของ File |
getLastUpdated() | Date | รับข้อมูลวันที่อัปเดตล่าสุดของ File |
getMimeType() | String | รับประเภท MIME ของไฟล์ |
getName() | String | รับชื่อของ File |
getOwner() | User | รับเจ้าของไฟล์ |
getParents() | FolderIterator | รับคอลเล็กชันโฟลเดอร์ที่เป็นผู้ปกครองของ File ทันที |
getResourceKey() | String | รับคีย์ทรัพยากรของ File ที่ต้องใช้เพื่อเข้าถึงรายการที่แชร์โดยใช้ลิงก์ |
getSecurityUpdateEligible() | Boolean | ดูว่า File นี้มีสิทธิ์นําการอัปเดตความปลอดภัยที่จําเป็นต้องมีคีย์การเข้าถึงสําหรับการเข้าถึงไปใช้ผ่านลิงก์ที่แชร์หรือไม่ |
getSecurityUpdateEnabled() | Boolean | ระบุว่า File นี้ต้องใช้คีย์ทรัพยากรเพื่อสิทธิ์เข้าถึงเมื่อแชร์โดยใช้ลิงก์หรือไม่ |
getSharingAccess() | Access | จัดว่าชั้นเรียนใดมีสิทธิ์เข้าถึง File นอกเหนือจากผู้ใช้ที่ได้รับสิทธิ์เป็นกรณีพิเศษ |
getSharingPermission() | Permission | ได้รับสิทธิ์ที่มอบให้ผู้ใช้ที่เข้าถึง File ได้ นอกเหนือจากผู้ใช้ที่ได้รับสิทธิ์อย่างชัดเจน |
getSize() | Integer | รับจํานวนไบต์ที่ใช้จัดเก็บ File ในไดรฟ์ |
getTargetId() | String | หากเป็นทางลัด ก็จะแสดงผลรหัสของรายการที่ชี้ไป |
getTargetMimeType() | String | หากเป็นทางลัด ให้แสดงประเภท MIME ของรายการที่ชี้ไป |
getTargetResourceKey() | String | ถ้าไฟล์เป็นทางลัด ให้แสดงรหัสทรัพยากรของรายการที่ชี้ไปยังไฟล์ดังกล่าว |
getThumbnail() | Blob | รับภาพขนาดย่อสําหรับไฟล์ หรือ null หากไม่มีภาพขนาดย่อ |
getUrl() | String | รับ URL ที่ใช้เปิด File ในแอป Google เช่น ไดรฟ์หรือเอกสารได้ |
getViewers() | User[] | รับรายการผู้ชมและผู้แสดงความคิดเห็นสําหรับ File นี้ |
isShareableByEditors() | Boolean | ตรวจสอบว่าผู้ใช้ที่มีสิทธิ์ในการแก้ไขกับ File ได้รับอนุญาตให้แชร์กับผู้ใช้คนอื่นหรือเปลี่ยนสิทธิ์ได้หรือไม่ |
isStarred() | Boolean | กําหนดได้ว่าระบบติดดาว File ในไดรฟ์ของผู้ใช้หรือไม่ |
isTrashed() | Boolean | กําหนดว่าจะให้ File อยู่ในถังขยะของไดรฟ์ของผู้ใช้หรือไม่ |
makeCopy() | File | สร้างสําเนาของไฟล์ |
makeCopy(destination) | File | สร้างสําเนาของไฟล์ในไดเรกทอรีปลายทาง |
makeCopy(name) | File | สร้างสําเนาของไฟล์และตั้งชื่อด้วยชื่อที่ให้มา |
makeCopy(name, destination) | File | สร้างสําเนาของไฟล์ในไดเรกทอรีปลายทางและตั้งชื่อโดยใช้ชื่อที่ให้ไว้ |
moveTo(destination) | File | ย้ายรายการนี้ไปยังโฟลเดอร์ปลายทางที่ระบุ |
removeCommenter(emailAddress) | File | นําผู้ใช้ที่ระบุออกจากรายการผู้แสดงความคิดเห็นสําหรับFile |
removeCommenter(user) | File | นําผู้ใช้ที่ระบุออกจากรายการผู้แสดงความคิดเห็นสําหรับFile |
removeEditor(emailAddress) | File | นําผู้ใช้ที่ระบุออกจากรายการผู้แก้ไขสําหรับ File |
removeEditor(user) | File | นําผู้ใช้ที่ระบุออกจากรายการผู้แก้ไขสําหรับ File |
removeViewer(emailAddress) | File | นําผู้ใช้ที่ระบุออกจากรายการผู้ชมและผู้แสดงความคิดเห็นสําหรับ File |
removeViewer(user) | File | นําผู้ใช้ที่ระบุออกจากรายการผู้ชมและผู้แสดงความคิดเห็นสําหรับ File |
revokePermissions(emailAddress) | File | ยกเลิกสิทธิ์การเข้าถึง File ที่ให้แก่ผู้ใช้ที่ระบุ |
revokePermissions(user) | File | ยกเลิกสิทธิ์การเข้าถึง File ที่ให้แก่ผู้ใช้ที่ระบุ |
setContent(content) | File | เขียนทับเนื้อหาของไฟล์ด้วยการแทนที่ที่ระบุ |
setDescription(description) | File | กําหนดคําอธิบายสําหรับ File |
setName(name) | File | ตั้งชื่อให้ File |
setOwner(emailAddress) | File | เปลี่ยนเจ้าของ File |
setOwner(user) | File | เปลี่ยนเจ้าของ File |
setSecurityUpdateEnabled(enabled) | File | ตั้งค่าว่า File ต้องใช้คีย์ทรัพยากรหรือไม่สําหรับการเข้าถึงผ่านการแชร์โดยใช้ลิงก์ |
setShareableByEditors(shareable) | File | ตั้งค่าว่าผู้ใช้ที่มีสิทธิ์แก้ไข File ได้รับอนุญาตให้แชร์กับผู้ใช้คนอื่นหรือเปลี่ยนสิทธิ์ได้หรือไม่ |
setSharing(accessType, permissionType) | File | ตั้งค่าชั้นเรียนของผู้ใช้ที่สามารถเข้าถึง File และสิทธิ์ต่างๆ ที่ผู้ใช้จะได้รับ นอกเหนือจากผู้ใช้ที่ได้รับสิทธิ์เข้าถึงอย่างชัดแจ้ง |
setStarred(starred) | File | ตั้งค่าว่าจะติดดาว File ในไดรฟ์ของผู้ใช้หรือไม่ |
setTrashed(trashed) | File | กําหนดว่าจะให้ File อยู่ในถังขยะของไดรฟ์ของผู้ใช้หรือไม่ |
เอกสารโดยละเอียด
addCommenter(emailAddress)
เพิ่มผู้ใช้ที่ต้องการลงในรายการผู้แสดงความคิดเห็นสําหรับ File
หากผู้ใช้อยู่ในรายการผู้ชมอยู่แล้ว เมธอดนี้จะโปรโมตผู้ใช้จากรายชื่อผู้ดู
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace 'cloudysanfrancisco@gmail.com' with the email address that you // want to add as a commenter. while (files.hasNext()) { const file = files.next(); email = 'cloudysanfrancisco@gmail.com'; console.log(file.addCommenter(email)); }
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
emailAddress | String | ที่อยู่อีเมลของผู้ใช้ที่จะเพิ่ม |
ขากลับ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
addCommenter(user)
เพิ่มผู้ใช้ที่ต้องการลงในรายการผู้แสดงความคิดเห็นสําหรับ File
หากผู้ใช้อยู่ในรายการผู้ชมอยู่แล้ว เมธอดนี้จะโปรโมตผู้ใช้จากรายชื่อผู้ดู
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Adds the active user as a commenter. while (files.hasNext()) { const file = files.next(); file.addCommenter(Session.getActiveUser()); }
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
user | User | การแสดงผู้ใช้ที่จะเพิ่ม |
ขากลับ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
addCommenters(emailAddresses)
เพิ่มอาร์เรย์ผู้ใช้ที่ระบุลงในรายการผู้แสดงความคิดเห็นสําหรับ File
หากผู้ใช้คนใดคนหนึ่งอยู่ในรายการผู้ชมอยู่แล้ว วิธีนี้โปรโมตพวกเขาจากรายการผู้ชม
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); while (files.hasNext()) { const file = files.next(); // TODO(developer): Replace 'cloudysanfrancisco@gmail.com' and // 'baklavainthebalkans@gmail.com' with the email addresses to add as commenters. const emails = ['cloudysanfrancisco@gmail.com','baklavainthebalkans@gmail.com']; console.log(file.addCommenters(emails)); }
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
emailAddresses | String[] | อาร์เรย์ของอีเมลของผู้ใช้ที่จะเพิ่ม |
ขากลับ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
addEditor(emailAddress)
เพิ่มผู้ใช้ที่ต้องการลงในรายการเครื่องมือแก้ไขของ File
หากผู้ใช้อยู่ในรายการผู้ชมแล้ว
วิธีนี้จะทําให้ผู้ใช้ไม่ได้อยู่ในรายการผู้ดู
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
emailAddress | String | ที่อยู่อีเมลของผู้ใช้ที่จะเพิ่ม |
ขากลับ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
addEditor(user)
เพิ่มผู้ใช้ที่ต้องการลงในรายการเครื่องมือแก้ไขของ File
หากผู้ใช้อยู่ในรายการผู้ชมแล้ว
วิธีนี้จะทําให้ผู้ใช้ไม่ได้อยู่ในรายการผู้ดู
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
user | User | การแสดงผู้ใช้ที่จะเพิ่ม |
ขากลับ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
addEditors(emailAddresses)
เพิ่มอาร์เรย์ผู้ใช้ที่ระบุลงในรายการผู้แก้ไขสําหรับ File
หากผู้ใช้คนใดคนหนึ่งอยู่ในรายการผู้ชมแล้ว วิธีนี้โปรโมตพวกเขาจากรายการผู้ชม
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
emailAddresses | String[] | อาร์เรย์ของอีเมลของผู้ใช้ที่จะเพิ่ม |
ขากลับ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
addViewer(emailAddress)
เพิ่มผู้ใช้ที่ต้องการลงในรายการผู้ชมสําหรับ File
หากผู้ใช้อยู่ในรายชื่อผู้แก้ไข
แล้ว เมธอดนี้จะไม่ส่งผลใดๆ
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
emailAddress | String | ที่อยู่อีเมลของผู้ใช้ที่จะเพิ่ม |
ขากลับ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
addViewer(user)
addViewers(emailAddresses)
เพิ่มอาร์เรย์ผู้ใช้ที่ระบุลงในรายการผู้ชมสําหรับ File
หากผู้ใช้คนใดคนหนึ่งอยู่ในรายการผู้แก้ไขอยู่แล้ว วิธีนี้จะไม่มีผลใดๆ
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
emailAddresses | String[] | อาร์เรย์ของอีเมลของผู้ใช้ที่จะเพิ่ม |
ขากลับ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
getAccess(email)
ได้รับสิทธิ์ที่ผู้ใช้ดังกล่าวได้รับ
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
email | String | อีเมลของผู้ใช้ที่ควรตรวจสอบสิทธิ์ |
ขากลับ
Permission
— สิทธิ์ที่มอบหมายให้กับผู้ใช้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getAccess(user)
ได้รับสิทธิ์ที่ผู้ใช้ดังกล่าวได้รับ
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
user | User | การแสดงสิทธิ์ของผู้ใช้ที่ควรตรวจสอบ |
ขากลับ
Permission
— สิทธิ์ที่มอบหมายให้กับผู้ใช้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getAs(contentType)
ส่งคืนข้อมูลภายในออบเจ็กต์นี้เป็น Blob ที่แปลงเป็นประเภทเนื้อหาที่ระบุ วิธีนี้เพิ่มส่วนขยายที่เหมาะสมลงในชื่อไฟล์ เช่น "myfile.pdf" อย่างไรก็ตามมีการสันนิษฐานว่าส่วนของชื่อไฟล์ที่ตามหลังเครื่องหมายจุดสุดท้าย (ถ้ามี) คือส่วนขยายที่มีอยู่ซึ่งควรแทนที่ ดังนั้น "ShoppingList.12.25.2014" จะกลายเป็น "ShoppingList.12.25.pdf"
หากต้องการดูโควต้า Conversion รายวัน โปรดดูโควต้าสําหรับบริการของ Google โดเมน Google Workspace ที่สร้างขึ้นใหม่อาจขึ้นอยู่กับโควต้าชั่วคราว
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
contentType | String | ประเภท MIME ที่จะแปลงเป็น สําหรับ Blob ส่วนใหญ่ 'application/pdf' เป็นตัวเลือกเดียวที่ใช้ได้ สําหรับรูปภาพในรูปแบบ BMP, GIF, JPEG หรือ PNG จะสามารถใช้ 'image/bmp' , 'image/gif' , 'image/jpeg' หรือ 'image/png' ได้ |
ขากลับ
Blob
— ข้อมูลในรูปแบบ BLOB
getBlob()
getDateCreated()
getDescription()
getDownloadUrl()
รับ URL ที่ใช้ดาวน์โหลดไฟล์ได้ ผู้ใช้ที่มีสิทธิ์เปิดไฟล์ใน Google ไดรฟ์เท่านั้น
ที่สามารถเข้าถึง URL คุณสามารถใช้ URL นี้ในเบราว์เซอร์เพื่อดาวน์โหลดไฟล์ แต่ไม่สามารถใช้เรียกไฟล์ด้วย UrlFetchApp
ถ้าต้องการเนื้อหาในไฟล์
ในสคริปต์ ให้ใช้ getBlob()
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Loops through the files and logs the download URLs to the console. while (files.hasNext()) { const file = files.next(); console.log(file.getDownloadUrl()); }
ขากลับ
String
— URL ที่ใช้ดาวน์โหลดไฟล์ได้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getEditors()
รับรายชื่อผู้แก้ไขสําหรับ File
นี้ หากผู้ใช้ที่เรียกใช้สคริปต์ไม่มีสิทธิ์แก้ไข File
เมธอดนี้จะส่งคืนอาร์เรย์ที่ว่างเปล่า
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Loops through the files. while (files.hasNext()) { const file = files.next(); // Adds the email addresses in the array as editors of each file. // TODO(developer): Replace 'cloudysanfrancisco@gmail.com' // and 'baklavainthebalkans@gmail.com' with valid email addresses. file.addEditors(['cloudysanfrancisco@gmail.com', 'baklavainthebalkans@gmail.com']); // Gets a list of the file editors. const editors = file.getEditors(); // For each file, logs the editors' email addresses to the console. for (const editor of editors) { console.log(editor.getEmail()); } }
ขากลับ
User[]
— หากผู้ใช้มีสิทธิ์ในการแก้ไขสําหรับ File
นี้ จะแสดงผลรายการเอดิเตอร์ หากผู้ใช้ไม่มีสิทธิ์แก้ไข จะแสดงผลอาร์เรย์ที่ว่างเปล่า
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getId()
getLastUpdated()
getMimeType()
รับประเภท MIME ของไฟล์
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Loops through the files and logs the MIME type to the console. while (files.hasNext()) { const file = files.next(); console.log(file.getMimeType()); }
ขากลับ
String
— ประเภท MIME ของไฟล์
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getName()
getOwner()
รับเจ้าของไฟล์
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Loops through the files and logs the names of the file owners to the console. while (files.hasNext()) { const file = files.next(); console.log(file.getOwner().getName()); }
ขากลับ
User
— เจ้าของไฟล์
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getParents()
รับคอลเล็กชันโฟลเดอร์ที่เป็นผู้ปกครองของ File
ทันที
ขากลับ
FolderIterator
คอลเล็กชันของโฟลเดอร์ที่เป็นพ่อแม่ของ File
โดยตรง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getResourceKey()
getSecurityUpdateEligible()
ดูว่า File
นี้มีสิทธิ์นําการอัปเดตความปลอดภัยที่จําเป็นต้องมีคีย์การเข้าถึงสําหรับการเข้าถึงไปใช้ผ่านลิงก์ที่แชร์หรือไม่
ไดรฟ์ต้องใช้คีย์ทรัพยากรเพื่อเข้าถึงไฟล์หรือโฟลเดอร์บางรายการที่แชร์โดยใช้ลิงก์ การเปลี่ยนแปลงนี้เป็นส่วนหนึ่งของการอัปเดตความปลอดภัย การอัปเดตสําหรับไฟล์และโฟลเดอร์ที่มีสิทธิ์
จะเปิดอยู่โดยค่าเริ่มต้น หากต้องการเปิดหรือปิดข้อกําหนดคีย์ทรัพยากรสําหรับไฟล์ที่มีสิทธิ์ ให้ใช้ setSecurityUpdateEnabled
เรียนรู้เพิ่มเติมเกี่ยวกับการอัปเดตความปลอดภัยสําหรับ Google ไดรฟ์
ขากลับ
Boolean
— ระบุว่าจะใช้ข้อกําหนดคีย์ทรัพยากรสําหรับ File
ได้หรือไม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getSecurityUpdateEnabled()
ระบุว่า File
นี้ต้องใช้คีย์ทรัพยากรเพื่อสิทธิ์เข้าถึงเมื่อแชร์โดยใช้ลิงก์หรือไม่ ระบบจะเปิดข้อกําหนดนี้โดยค่าเริ่มต้นสําหรับไฟล์และโฟลเดอร์ที่มีสิทธิ์
หากต้องการเปิดหรือปิดข้อกําหนดคีย์ทรัพยากรสําหรับไฟล์ที่มีสิทธิ์ ให้ใช้
setSecurityUpdateEnabled
เรียนรู้เพิ่มเติมเกี่ยวกับการอัปเดตความปลอดภัยสําหรับ Google ไดรฟ์
ขากลับ
Boolean
— ระบุว่าข้อกําหนดคีย์ทรัพยากรเปิดใช้สําหรับ File
นี้หรือไม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getSharingAccess()
จัดว่าชั้นเรียนใดมีสิทธิ์เข้าถึง File
นอกเหนือจากผู้ใช้ที่ได้รับสิทธิ์เป็นกรณีพิเศษ
ขากลับ
Access
— ผู้ใช้ที่มีสิทธิ์เข้าถึง File
ระดับใด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getSharingPermission()
ได้รับสิทธิ์ที่มอบให้ผู้ใช้ที่เข้าถึง File
ได้ นอกเหนือจากผู้ใช้ที่ได้รับสิทธิ์อย่างชัดเจน
ขากลับ
Permission
— สิทธิ์ที่มอบให้ผู้ใช้ที่สามารถเข้าถึง File
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getSize()
รับจํานวนไบต์ที่ใช้จัดเก็บ File
ในไดรฟ์ โปรดทราบว่าไฟล์แอปพลิเคชัน Google Workspace จะไม่นับรวมในขีดจํากัดของพื้นที่เก็บข้อมูล Google ไดรฟ์ ดังนั้นจึงจะแสดงผล
0
ไบต์
ขากลับ
Integer
— จํานวนไบต์ที่ใช้จัดเก็บ File
ในไดรฟ์
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getTargetId()
หากเป็นทางลัด ก็จะแสดงผลรหัสของรายการที่ชี้ไป
มิฉะนั้นจะแสดงผล null
// The ID of the file for which to make a shortcut and the ID of // the folder to which you want to add the shortcut. // TODO(developer): Replace the file and folder IDs with your IDs. const fileId = 'abc123456'; const folderId = 'xyz987654'; // Gets the folder to add the shortcut to. const folder = DriveApp.getFolderById(folderId); // Creates a shortcut of the file and moves it to the specified folder. const shortcut = DriveApp.createShortcut(fileId).moveTo(folder); // Logs the target ID of the shortcut. console.log(`${shortcut.getName()}=${shortcut.getTargetId()}`);
ขากลับ
String
— รหัสรายการเป้าหมาย
getTargetMimeType()
หากเป็นทางลัด ให้แสดงประเภท MIME ของรายการที่ชี้ไป
มิฉะนั้นจะแสดงผล null
// The ID of the file for which to make a shortcut and the ID of // the folder to which you want to add the shortcut. // TODO(developer): Replace the file and folder IDs with your IDs. const fileId = 'abc123456'; const folderId = 'xyz987654'; // Gets the folder to add the shortcut to. const folder = DriveApp.getFolderById(folderId); // Creates a shortcut of the file and moves it to the specified folder. const shortcut = DriveApp.createShortcut(fileId).moveTo(folder); // Logs the MIME type of the file that the shortcut points to. console.log(`MIME type of the shortcut: ${shortcut.getTargetMimeType()}`);
ขากลับ
String
— ประเภท MIME ของรายการเป้าหมาย
getTargetResourceKey()
ถ้าไฟล์เป็นทางลัด ให้แสดงรหัสทรัพยากรของรายการที่ชี้ไปยังไฟล์ดังกล่าว คีย์ทรัพยากรคือพารามิเตอร์เพิ่มเติมที่จะต้องส่งผ่านเพื่อเข้าถึงไฟล์ที่แชร์โดยใช้ลิงก์
หากไฟล์ไม่ใช่ทางลัด จะแสดงผล null
ขากลับ
String
— คีย์ทรัพยากรของรายการเป้าหมายหรือ null
หากไฟล์ไม่ใช่ทางลัด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getThumbnail()
รับภาพขนาดย่อสําหรับไฟล์ หรือ null
หากไม่มีภาพขนาดย่อ
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Loops through the files. while (files.hasNext()) { const file = files.next(); // Logs the thumbnail image for each file to the console as a blob, // or null if no thumbnail exists. console.log(file.getThumbnail()); }
ขากลับ
Blob
— ภาพขนาดย่อสําหรับไฟล์
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getUrl()
รับ URL ที่ใช้เปิด File
ในแอป Google เช่น ไดรฟ์หรือเอกสารได้
ขากลับ
String
— URL ที่สามารถใช้ดู File
นี้ในแอป Google เช่น ไดรฟ์หรือเอกสาร
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getViewers()
รับรายการผู้ชมและผู้แสดงความคิดเห็นสําหรับ File
นี้ หากผู้ใช้ที่เรียกใช้สคริปต์ไม่มีสิทธิ์แก้ไข File
เมธอดนี้จะส่งคืนอาร์เรย์ที่ว่างเปล่า
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Loops through the files. while (files.hasNext()) { const file = files.next(); // For each file, logs the viewers' email addresses to the console. const viewers = file.getViewers(); for (viewer of viewers) { console.log(viewer.getEmail()); } }
ขากลับ
User[]
— หากผู้ใช้มีสิทธิ์ในการแก้ไขสําหรับ File
นี้ จะส่งกลับรายการผู้ดูและผู้แสดงความคิดเห็น หากผู้ใช้ไม่มีสิทธิ์แก้ไข จะแสดงผลอาร์เรย์ที่ว่างเปล่า
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
isStarred()
กําหนดได้ว่าระบบติดดาว File
ในไดรฟ์ของผู้ใช้หรือไม่
ขากลับ
Boolean
— true
หากติดดาว File
ในไดรฟ์ของผู้ใช้ แต่ false
หากไม่มีการติดดาว
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
isTrashed()
กําหนดว่าจะให้ File
อยู่ในถังขยะของไดรฟ์ของผู้ใช้หรือไม่
ขากลับ
Boolean
— true
หาก File
อยู่ในถังขยะในไดรฟ์ของผู้ใช้
false
หากไม่ได้อยู่ในถังขยะ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
makeCopy()
สร้างสําเนาของไฟล์
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Loops through the files. while (files.hasNext()) { const file = files.next(); // Creates a copy of each file and logs the file name to the console. console.log(file.makeCopy().getName()); }
ขากลับ
File
— สําเนาใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
makeCopy(destination)
สร้างสําเนาของไฟล์ในไดเรกทอรีปลายทาง
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Loops through the files. while (files.hasNext()) { const file = files.next(); // Creates a copy of each file and adds it to the specified folder. // TODO(developer): Replace the folder ID with your own. const destination = DriveApp.getFolderById('123456abcxyz'); const copiedFile = file.makeCopy(destination); // Logs the file names to the console. console.log(copiedFile.getName()); }
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
destination | Folder | ไดเรกทอรีที่จะคัดลอกไฟล์ไป |
ขากลับ
File
— สําเนาใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
makeCopy(name)
สร้างสําเนาของไฟล์และตั้งชื่อด้วยชื่อที่ให้มา
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Loops through the files. while (files.hasNext()) { const file = files.next(); // Creates a copy of each file and sets the name to 'Test-Copy.' const filename = file.makeCopy('Test-Copy'); // Logs the copied file's name to the console. console.log(filename.getName()); }
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
name | String | ชื่อไฟล์ที่จะใช้กับสําเนาใหม่ |
ขากลับ
File
— สําเนาใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
makeCopy(name, destination)
สร้างสําเนาของไฟล์ในไดเรกทอรีปลายทางและตั้งชื่อโดยใช้ชื่อที่ให้ไว้
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Loops through the files. while (files.hasNext()) { const file = files.next(); // Creates a copy of each file, sets the file name, and adds the copied file // to the specified folder. // TODO(developer): Replace the folder ID with your own. const destination = DriveApp.getFolderById('123456abcxyz'); const copiedFile = file.makeCopy('Test-Copy', destination); // Logs the file names to the console. console.log(copiedFile.getName()); }
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
name | String | ชื่อไฟล์ที่จะใช้กับสําเนาใหม่ |
destination | Folder | ไดเรกทอรีที่จะคัดลอกไฟล์ไป |
ขากลับ
File
— สําเนาใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
moveTo(destination)
ย้ายรายการนี้ไปยังโฟลเดอร์ปลายทางที่ระบุ
ผู้ใช้ปัจจุบันต้องเป็นเจ้าของไฟล์หรือมีสิทธิ์แก้ไขเป็นอย่างน้อยในโฟลเดอร์หลักรายการปัจจุบัน เพื่อย้ายรายการไปยังโฟลเดอร์ปลายทาง
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
destination | Folder | โฟลเดอร์ที่จะกลายเป็นโฟลเดอร์ระดับบนสุดใหม่ |
ขากลับ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
removeCommenter(emailAddress)
นําผู้ใช้ที่ระบุออกจากรายการผู้แสดงความคิดเห็นสําหรับFile
วิธีการนี้จะไม่บล็อกผู้ใช้ไม่ให้เข้าถึง File
หากผู้ใช้เป็นสมาชิกในชั้นเรียนที่มีสิทธิ์เข้าถึงทั่วไป เช่น หากแชร์ File
กับโดเมนทั้งหมดของผู้ใช้
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Loops through the files. while (files.hasNext()) { const file = files.next(); // Removes the given user from the list of commenters for each file. // TODO(developer): Replace the email with the email of the user you want to remove. file.removeCommenter('cloudysanfrancisco@gmail.com'); }
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
emailAddress | String | ที่อยู่อีเมลของผู้ใช้ที่จะนําออก |
ขากลับ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
removeCommenter(user)
นําผู้ใช้ที่ระบุออกจากรายการผู้แสดงความคิดเห็นสําหรับFile
วิธีการนี้จะไม่บล็อกผู้ใช้ไม่ให้เข้าถึง File
หากผู้ใช้เป็นสมาชิกในชั้นเรียนที่มีสิทธิ์เข้าถึงทั่วไป เช่น หากแชร์ File
กับโดเมนทั้งหมดของผู้ใช้
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Loops through the files. while (files.hasNext()) { const file = files.next(); // Removes the given user from the list of commenters for each file. console.log(file.removeCommenter(Session.getActiveUser())); }
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
user | User | การแสดงผู้ใช้ที่จะนําออก |
ขากลับ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
removeEditor(emailAddress)
นําผู้ใช้ที่ระบุออกจากรายการผู้แก้ไขสําหรับ File
วิธีการนี้จะไม่บล็อกผู้ใช้ไม่ให้เข้าถึง File
หากผู้ใช้เป็นสมาชิกในชั้นเรียนที่มีสิทธิ์เข้าถึงทั่วไป เช่น หากมีการแชร์ File
กับทั้งโดเมนของผู้ใช้ หรือหาก File
อยู่ในไดรฟ์ที่แชร์ที่ผู้ใช้เข้าถึงได้
สําหรับไฟล์ในไดรฟ์ การดําเนินการนี้จะนําผู้ใช้ออกจากรายชื่อผู้ดูด้วย
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
emailAddress | String | ที่อยู่อีเมลของผู้ใช้ที่จะนําออก |
ขากลับ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
removeEditor(user)
นําผู้ใช้ที่ระบุออกจากรายการผู้แก้ไขสําหรับ File
วิธีการนี้จะไม่บล็อกผู้ใช้ไม่ให้เข้าถึง File
หากผู้ใช้เป็นสมาชิกในชั้นเรียนที่มีสิทธิ์เข้าถึงทั่วไป เช่น หากมีการแชร์ File
กับทั้งโดเมนของผู้ใช้ หรือหาก File
อยู่ในไดรฟ์ที่แชร์ที่ผู้ใช้เข้าถึงได้
สําหรับไฟล์ในไดรฟ์ การดําเนินการนี้จะนําผู้ใช้ออกจากรายชื่อผู้ดูด้วย
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
user | User | การแสดงผู้ใช้ที่จะนําออก |
ขากลับ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
removeViewer(emailAddress)
นําผู้ใช้ที่ระบุออกจากรายการผู้ชมและผู้แสดงความคิดเห็นสําหรับ File
วิธีการนี้จะไม่มีผลหากผู้ใช้เป็นผู้แก้ไข ไม่ใช่ผู้ดูหรือผู้แสดงความคิดเห็น วิธีการนี้จะไม่บล็อกผู้ใช้ไม่ให้เข้าถึง File
หากผู้ใช้เป็นสมาชิกในชั้นเรียนที่มีสิทธิ์เข้าถึงทั่วไป เช่น หากมีการแชร์ File
กับทั้งโดเมนของผู้ใช้ หรือหาก File
อยู่ในไดรฟ์ที่แชร์ที่ผู้ใช้เข้าถึงได้
สําหรับไฟล์ในไดรฟ์ การดําเนินการนี้จะนําผู้ใช้ออกจากรายชื่อผู้แก้ไขด้วย
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
emailAddress | String | ที่อยู่อีเมลของผู้ใช้ที่จะนําออก |
ขากลับ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
removeViewer(user)
นําผู้ใช้ที่ระบุออกจากรายการผู้ชมและผู้แสดงความคิดเห็นสําหรับ File
วิธีการนี้จะไม่มีผลหากผู้ใช้เป็นผู้แก้ไข ไม่ใช่ผู้ดู วิธีการนี้จะไม่บล็อกผู้ใช้ไม่ให้เข้าถึง File
หากผู้ใช้เป็นสมาชิกในชั้นเรียนที่มีสิทธิ์เข้าถึงทั่วไป เช่น หากมีการแชร์ File
กับทั้งโดเมนของผู้ใช้ หรือหาก File
อยู่ในไดรฟ์ที่แชร์ที่ผู้ใช้เข้าถึงได้
สําหรับไฟล์ในไดรฟ์ การดําเนินการนี้จะนําผู้ใช้ออกจากรายชื่อผู้แก้ไขด้วย
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
user | User | การแสดงผู้ใช้ที่จะนําออก |
ขากลับ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
revokePermissions(emailAddress)
ยกเลิกสิทธิ์การเข้าถึง File
ที่ให้แก่ผู้ใช้ที่ระบุ วิธีการนี้จะไม่บล็อกผู้ใช้ไม่ให้เข้าถึง File
หากผู้ใช้เป็นสมาชิกในชั้นเรียนที่มีสิทธิ์เข้าถึงทั่วไป เช่น หากแชร์ File
กับโดเมนทั้งหมดของผู้ใช้
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
emailAddress | String | อีเมลของผู้ใช้ที่ต้องการเพิกถอนสิทธิ์เข้าถึง |
ขากลับ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
revokePermissions(user)
ยกเลิกสิทธิ์การเข้าถึง File
ที่ให้แก่ผู้ใช้ที่ระบุ วิธีการนี้จะไม่บล็อกผู้ใช้ไม่ให้เข้าถึง File
หากผู้ใช้เป็นสมาชิกในชั้นเรียนที่มีสิทธิ์เข้าถึงทั่วไป เช่น หากแชร์ File
กับโดเมนทั้งหมดของผู้ใช้
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
user | User | การนําเสนอผู้ใช้ที่ถูกเพิกถอนสิทธิ์เข้าถึง |
ขากลับ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
setContent(content)
เขียนทับเนื้อหาของไฟล์ด้วยการแทนที่ที่ระบุ มีข้อยกเว้นหาก content
มีขนาดใหญ่กว่า 10 MB
// Creates a text file with the content 'Hello, world!' file = DriveApp.createFile('New Text File', 'Hello, world!'); // Logs the content of the text file to the console. console.log(file.getBlob().getDataAsString()); // Updates the content of the text file to 'Updated text!' file.setContent('Updated text!') // Logs content of the text file to the console. console.log(file.getBlob().getDataAsString());
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
content | String | เนื้อหาใหม่ของไฟล์ |
ขากลับ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
setDescription(description)
setName(name)
setOwner(emailAddress)
setOwner(user)
setSecurityUpdateEnabled(enabled)
ตั้งค่าว่า File
ต้องใช้คีย์ทรัพยากรหรือไม่สําหรับการเข้าถึงผ่านการแชร์โดยใช้ลิงก์ ระบบจะเปิดใช้ไฟล์และโฟลเดอร์ที่มีสิทธิ์โดยค่าเริ่มต้น
เรียนรู้เพิ่มเติมเกี่ยวกับการอัปเดตความปลอดภัยสําหรับ Google ไดรฟ์
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
enabled | Boolean | เลือกว่าจะเปิดใช้ข้อกําหนดคีย์ทรัพยากรสําหรับ File หรือไม่ |
ขากลับ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
setSharing(accessType, permissionType)
ตั้งค่าชั้นเรียนของผู้ใช้ที่สามารถเข้าถึง File
และสิทธิ์ต่างๆ ที่ผู้ใช้จะได้รับ นอกเหนือจากผู้ใช้ที่ได้รับสิทธิ์เข้าถึงอย่างชัดแจ้ง
// Creates a folder that anyone on the Internet can read from and write to. (Domain // administrators can prohibit this setting for users of a Google Workspace domain.) var folder = DriveApp.createFolder('Shared Folder'); folder.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.EDIT);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
accessType | Access | ผู้ใช้ประเภทใดที่ควรสามารถเข้าถึง File |
permissionType | Permission | สิทธิ์ที่ควรมอบให้กับผู้ใช้ที่เข้าถึง File ได้ |
ขากลับ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
setStarred(starred)
ตั้งค่าว่าจะติดดาว File
ในไดรฟ์ของผู้ใช้หรือไม่ ค่าเริ่มต้นสําหรับ File
ใหม่คือ false
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
starred | Boolean | true ถ้ามีการติดดาว File ในไดรฟ์ของผู้ใช้; false หากไม่ควรติดดาว |
ขากลับ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
setTrashed(trashed)
กําหนดว่าจะให้ File
อยู่ในถังขยะของไดรฟ์ของผู้ใช้หรือไม่ มีเพียงเจ้าของเท่านั้นที่สามารถทิ้ง File
ค่าเริ่มต้นสําหรับ File
ใหม่คือ false
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
trashed | Boolean | true ถ้ามีการย้าย File ไปที่ถังขยะของไดรฟ์ของผู้ใช้ ส่วน false ถ้าไม่ใช่ |
ขากลับ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive