ไฟล์ใน 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)
เพิ่มผู้ใช้ที่ระบุลงในรายการผู้ชมสำหรับ File
หากผู้ใช้อยู่ในรายการเอดิเตอร์อยู่แล้ว วิธีการนี้จะไม่มีผล
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
user | User | ตัวแทนของผู้ใช้ที่จะเพิ่ม |
รีเทิร์น
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับสิทธิ์จากขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
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
// Gets a file by its ID. // TODO(developer): Replace 'abc123456' with your file ID. const file = DriveApp.getFileById('abc123456'); // If the file is a shortcut, returns the resource key of the file that it points to. console.log(file.getTargetResourceKey());
รีเทิร์น
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()
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