ไฟล์ใน Google ไดรฟ์ คุณเข้าถึงหรือสร้างไฟล์ได้จาก Drive
// Trash every untitled spreadsheet that hasn't been updated in a week. const files = DriveApp.getFilesByName('Untitled spreadsheet'); while (files.hasNext()) { const file = files.next(); if (new Date() - file.getLastUpdated() > 7 * 24 * 60 * 60 * 1000) { file.setTrashed(true); } }
เมธอด
| วิธีการ | ประเภทการแสดงผล | รายละเอียดแบบย่อ |
|---|---|---|
add | File | เพิ่มผู้ใช้ที่ระบุลงในรายชื่อผู้แสดงความคิดเห็นสำหรับ File |
add | File | เพิ่มผู้ใช้ที่ระบุลงในรายชื่อผู้แสดงความคิดเห็นสำหรับ File |
add | File | เพิ่มอาร์เรย์ของผู้ใช้ที่ระบุลงในรายชื่อผู้แสดงความคิดเห็นสำหรับ File |
add | File | เพิ่มผู้ใช้ที่ระบุลงในรายชื่อเอดิเตอร์สำหรับ File |
add | File | เพิ่มผู้ใช้ที่ระบุลงในรายชื่อเอดิเตอร์สำหรับ File |
add | File | เพิ่มอาร์เรย์ของผู้ใช้ที่ระบุลงในรายชื่อผู้แก้ไขสำหรับ File |
add | File | เพิ่มผู้ใช้ที่ระบุลงในรายชื่อผู้ชมสำหรับ File |
add | File | เพิ่มผู้ใช้ที่ระบุลงในรายชื่อผู้ชมสำหรับ File |
add | File | เพิ่มอาร์เรย์ของผู้ใช้ที่ระบุลงในรายชื่อผู้ชมสำหรับ File |
get | Permission | รับสิทธิ์ที่มอบให้แก่ผู้ใช้ที่เฉพาะเจาะจง |
get | Permission | รับสิทธิ์ที่มอบให้แก่ผู้ใช้ที่เฉพาะเจาะจง |
get | Blob | แสดงผลข้อมูลภายในออบเจ็กต์นี้เป็น Blob ที่แปลงเป็นประเภทเนื้อหาที่ระบุ |
get | Blob | ส่งคืนข้อมูลภายในออบเจ็กต์นี้เป็น Blob |
get | Date | รับวันที่สร้าง File |
get | String | รับคำอธิบายสำหรับ File |
get | String | รับ URL ที่ใช้ดาวน์โหลดไฟล์ได้ |
get | User[] | รับรายชื่อเอดิเตอร์สำหรับ File นี้ |
get | String | รับรหัสของ File |
get | Date | รับวันที่อัปเดต File ครั้งล่าสุด |
get | String | รับประเภท MIME ของไฟล์ |
get | String | รับชื่อของ File |
get | User | รับเจ้าของไฟล์ |
get | Folder | รับคอลเล็กชันของโฟลเดอร์ที่เป็นโฟลเดอร์หลักของ File |
get | String | รับคีย์แหล่งข้อมูลของ File ที่จำเป็นต่อการเข้าถึงรายการที่
แชร์โดยใช้ลิงก์ |
get | Boolean | ระบุว่าFile มีสิทธิ์ใช้การอัปเดตความปลอดภัยที่ต้องใช้คีย์ทรัพยากรเพื่อเข้าถึงเมื่อแชร์โดยใช้ลิงก์หรือไม่ |
get | Boolean | ระบุว่า File ต้องใช้คีย์ทรัพยากรสำหรับการเข้าถึงเมื่อแชร์โดยใช้ลิงก์หรือไม่ |
get | Access | รับข้อมูลว่าผู้ใช้กลุ่มใดบ้างที่เข้าถึง File ได้ นอกเหนือจากผู้ใช้แต่ละรายที่ได้รับสิทธิ์เข้าถึงอย่างชัดเจน |
get | Permission | รับสิทธิ์ที่มอบให้แก่ผู้ใช้ที่เข้าถึง File ได้
นอกเหนือจากผู้ใช้แต่ละรายที่ได้รับสิทธิ์เข้าถึงอย่างชัดเจน |
get | Integer | รับจำนวนไบต์ที่ใช้จัดเก็บ File ในไดรฟ์ |
get | String | หากเป็นทางลัด จะแสดงรหัสของรายการที่ทางลัดชี้ไป |
get | String | หากเป็นทางลัด จะแสดงผลประเภท MIME ของรายการที่ทางลัดชี้ไป |
get | String | หากไฟล์เป็นทางลัด ระบบจะแสดงคีย์ทรัพยากรของรายการที่ไฟล์ชี้ไป |
get | Blob|null | รับภาพขนาดย่อของไฟล์ หรือ null หากไม่มีภาพขนาดย่อ |
get | String | รับ URL ที่ใช้เปิด File ในแอป Google เช่น
ไดรฟ์หรือเอกสารได้ |
get | User[] | รับรายการผู้มีสิทธิ์อ่านและผู้แสดงความคิดเห็นสำหรับ File นี้ |
is | Boolean | กำหนดว่าผู้ใช้ที่มีสิทธิ์แก้ไขใน File มีสิทธิ์แชร์กับผู้ใช้รายอื่นหรือเปลี่ยนสิทธิ์หรือไม่ |
is | Boolean | กำหนดว่ามีการติดดาว File ในไดรฟ์ของผู้ใช้หรือไม่ |
is | Boolean | กำหนดว่า File อยู่ในถังขยะของไดรฟ์ของผู้ใช้หรือไม่ |
make | File | สร้างสำเนาไฟล์ |
make | File | สร้างสำเนาของไฟล์ในไดเรกทอรีปลายทาง |
make | File | สร้างสำเนาของไฟล์และตั้งชื่อตามชื่อที่ระบุ |
make | File | สร้างสำเนาไฟล์ในไดเรกทอรีปลายทางและตั้งชื่อตามชื่อที่ระบุ |
move | File | ย้ายรายการนี้ไปยังโฟลเดอร์ปลายทางที่ระบุ |
remove | File | นำผู้ใช้ที่ระบุออกจากรายชื่อผู้แสดงความคิดเห็นสำหรับ File |
remove | File | นำผู้ใช้ที่ระบุออกจากรายชื่อผู้แสดงความคิดเห็นสำหรับ File |
remove | File | นำผู้ใช้ที่ระบุออกจากรายชื่อผู้แก้ไขสำหรับ File |
remove | File | นำผู้ใช้ที่ระบุออกจากรายชื่อผู้แก้ไขสำหรับ File |
remove | File | นำผู้ใช้ที่ระบุออกจากรายชื่อผู้ชมและผู้แสดงความคิดเห็นสำหรับFile |
remove | File | นำผู้ใช้ที่ระบุออกจากรายชื่อผู้ชมและผู้แสดงความคิดเห็นสำหรับFile |
revoke | File | เพิกถอนสิทธิ์เข้าถึง File ที่ให้แก่ผู้ใช้ที่ระบุ |
revoke | File | เพิกถอนสิทธิ์เข้าถึง File ที่ให้แก่ผู้ใช้ที่ระบุ |
set | File | เขียนทับเนื้อหาของไฟล์ด้วยการแทนที่ที่ระบุ |
set | File | ตั้งค่าคำอธิบายสำหรับ File |
set | File | ตั้งชื่อ File |
set | File | เปลี่ยนเจ้าของ File |
set | File | เปลี่ยนเจ้าของ File |
set | File | กำหนดว่า File ต้องใช้คีย์ทรัพยากรสำหรับการเข้าถึงหรือไม่เมื่อมีการแชร์โดยใช้ลิงก์ |
set | File | กำหนดว่าผู้ใช้ที่มีสิทธิ์แก้ไขFileจะแชร์กับผู้ใช้รายอื่นหรือเปลี่ยนสิทธิ์ได้หรือไม่ |
set | File | กำหนดว่าผู้ใช้กลุ่มใดสามารถเข้าถึง File และสิทธิ์ใดบ้าง
ที่ผู้ใช้เหล่านั้นได้รับ นอกเหนือจากผู้ใช้แต่ละรายที่ได้รับสิทธิ์เข้าถึงอย่างชัดแจ้ง |
set | File | กำหนดว่า File จะติดดาวในไดรฟ์ของผู้ใช้หรือไม่ |
set | File | กำหนดว่า File อยู่ในถังขยะของไดรฟ์ของผู้ใช้หรือไม่ |
เอกสารโดยละเอียด
add Commenter(emailAddress)
เพิ่มผู้ใช้ที่ระบุลงในรายชื่อผู้แสดงความคิดเห็นสำหรับ File หากผู้ใช้
อยู่ในรายชื่อผู้ชมอยู่แล้ว เมธอดนี้จะเลื่อนผู้ใช้รายดังกล่าวออกจากรายชื่อผู้ชม
const files = DriveApp.getFilesByName('Test'); // Loops through the files while (files.hasNext()) { const file = files.next(); file.addCommenter('hello@example.com'); }
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
email | String | อีเมลของผู้ใช้ที่จะเพิ่ม |
รีเทิร์น
File — This File, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
add Commenter(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()); }
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
user | User | การแสดงผู้ใช้ที่จะเพิ่ม |
รีเทิร์น
File — This File, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
add Commenters(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)); }
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
email | String[] | อาร์เรย์ของอีเมลของผู้ใช้ที่จะเพิ่ม |
รีเทิร์น
File — This File, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
add Editor(emailAddress)
เพิ่มผู้ใช้ที่ระบุลงในรายชื่อเอดิเตอร์สำหรับ File หากผู้ใช้
อยู่ในรายชื่อผู้ชมอยู่แล้ว วิธีนี้จะเลื่อนผู้ใช้รายดังกล่าวออกจากรายชื่อผู้ชม
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
email | String | อีเมลของผู้ใช้ที่จะเพิ่ม |
รีเทิร์น
File — This File, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
add Editor(user)
เพิ่มผู้ใช้ที่ระบุลงในรายชื่อเอดิเตอร์สำหรับ File หากผู้ใช้
อยู่ในรายชื่อผู้ชมอยู่แล้ว วิธีนี้จะเลื่อนผู้ใช้รายดังกล่าวออกจากรายชื่อผู้ชม
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
user | User | การแสดงผู้ใช้ที่จะเพิ่ม |
รีเทิร์น
File — This File, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
add Editors(emailAddresses)
เพิ่มอาร์เรย์ของผู้ใช้ที่ระบุลงในรายชื่อผู้แก้ไขสำหรับ File หากผู้ใช้รายใดอยู่ในรายชื่อผู้ชมอยู่แล้ว วิธีนี้จะเลื่อนผู้ใช้รายดังกล่าวออกจากรายชื่อผู้ชม
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
email | String[] | อาร์เรย์ของอีเมลของผู้ใช้ที่จะเพิ่ม |
รีเทิร์น
File — This File, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
add Viewer(emailAddress)
เพิ่มผู้ใช้ที่ระบุลงในรายชื่อผู้ชมสำหรับ File หากผู้ใช้
อยู่ในรายชื่อผู้แก้ไขอยู่แล้ว วิธีนี้จะไม่มีผล
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
email | String | อีเมลของผู้ใช้ที่จะเพิ่ม |
รีเทิร์น
File — This File, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
add Viewer(user)
เพิ่มผู้ใช้ที่ระบุลงในรายชื่อผู้ชมสำหรับ File หากผู้ใช้
อยู่ในรายชื่อผู้แก้ไขอยู่แล้ว วิธีนี้จะไม่มีผล
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
user | User | การแสดงผู้ใช้ที่จะเพิ่ม |
รีเทิร์น
File — This File, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
add Viewers(emailAddresses)
เพิ่มอาร์เรย์ของผู้ใช้ที่ระบุลงในรายชื่อผู้ชมสำหรับ File หากผู้ใช้รายใดอยู่ในรายชื่อผู้แก้ไขอยู่แล้ว วิธีนี้จะไม่มีผลกับผู้ใช้รายนั้น
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
email | String[] | อาร์เรย์ของอีเมลของผู้ใช้ที่จะเพิ่ม |
รีเทิร์น
File — This File, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
get Access(email)
รับสิทธิ์ที่มอบให้แก่ผู้ใช้ที่เฉพาะเจาะจง วิธีการนี้ไม่รองรับการคืนสิทธิ์สำหรับกลุ่ม Google หรือสิทธิ์ที่รับช่วงผ่านกลุ่ม Google
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
email | String | อีเมลของผู้ใช้ที่ควรตรวจสอบสิทธิ์ Google Groups ไม่รองรับ |
รีเทิร์น
Permission - สิทธิ์ที่มอบให้แก่ผู้ใช้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly -
https://www.googleapis.com/auth/drive
get Access(user)
รับสิทธิ์ที่มอบให้แก่ผู้ใช้ที่เฉพาะเจาะจง วิธีการนี้ไม่รองรับการคืนสิทธิ์สำหรับกลุ่ม Google หรือสิทธิ์ที่รับช่วงผ่านกลุ่ม Google
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
user | User | การแสดงผู้ใช้ที่ควรตรวจสอบสิทธิ์ |
รีเทิร์น
Permission - สิทธิ์ที่มอบให้แก่ผู้ใช้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly -
https://www.googleapis.com/auth/drive
get As(contentType)
แสดงผลข้อมูลภายในออบเจ็กต์นี้เป็น Blob ที่แปลงเป็นประเภทเนื้อหาที่ระบุ วิธีนี้จะเพิ่มนามสกุลที่เหมาะสมให้กับชื่อไฟล์ เช่น "myfile.pdf" อย่างไรก็ตาม ระบบจะ ถือว่าส่วนของชื่อไฟล์ที่อยู่หลังจุดสุดท้าย (หากมี) เป็นนามสกุลที่มีอยู่ ซึ่งควรแทนที่ ดังนั้น "ShoppingList.12.25.2014" จะกลายเป็น "ShoppingList.12.25.pdf"
หากต้องการดูโควต้ารายวันสำหรับ Conversion โปรดดูโควต้าสำหรับบริการของ Google โดเมน Google Workspace ที่สร้างขึ้นใหม่จะอยู่ภายใต้โควต้าที่เข้มงวดกว่าชั่วคราว
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
content | String | ประเภท MIME ที่จะแปลง สำหรับ Blob ส่วนใหญ่ 'application/pdf' เป็น
ตัวเลือกที่ใช้ได้เพียงตัวเลือกเดียว สำหรับรูปภาพในรูปแบบ BMP, GIF, JPEG หรือ PNG คุณยังใช้ 'image/bmp', 'image/gif', 'image/jpeg' หรือ 'image/png' ได้ด้วย
สำหรับเอกสาร Google เอกสาร 'text/markdown' ก็ใช้ได้เช่นกัน |
รีเทิร์น
Blob — ข้อมูลเป็น Blob
get Blob()
get Date Created()
get Description()
get Download Url()
รับ URL ที่ใช้ดาวน์โหลดไฟล์ได้ เฉพาะผู้ใช้ที่มีสิทธิ์เปิดไฟล์
ใน Google ไดรฟ์เท่านั้นที่จะเข้าถึง URL ได้ คุณใช้ URL นี้ในเบราว์เซอร์เพื่อดาวน์โหลดไฟล์ได้ แต่ใช้เพื่อดึงข้อมูลไฟล์ด้วย Url ไม่ได้ หากต้องการให้เนื้อหาของ
ไฟล์อยู่ในสคริปต์ ให้ใช้ get
// 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
get Editors()
รับรายชื่อเอดิเตอร์สำหรับ 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
get Id()
get Last Updated()
get Mime Type()
รับประเภท 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
get Name()
get Owner()
รับเจ้าของไฟล์
// 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
get Parents()
รับคอลเล็กชันของโฟลเดอร์ที่เป็นโฟลเดอร์หลักของ File
รีเทิร์น
Folder - คอลเล็กชันโฟลเดอร์ที่เป็นโฟลเดอร์หลักของ File
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly -
https://www.googleapis.com/auth/drive
get Resource Key()
get Security Update Eligible()
ระบุว่าFile มีสิทธิ์ใช้การอัปเดตความปลอดภัยที่ต้องใช้คีย์ทรัพยากรเพื่อเข้าถึงเมื่อแชร์โดยใช้ลิงก์หรือไม่
ไดรฟ์ต้องใช้คีย์แหล่งข้อมูลเพื่อเข้าถึงไฟล์หรือโฟลเดอร์บางรายการที่แชร์โดยใช้
ลิงก์ การเปลี่ยนแปลงนี้เป็นส่วนหนึ่งของการอัปเดตความปลอดภัย ระบบจะเปิดใช้การอัปเดตโดยค่าเริ่มต้นสำหรับไฟล์และโฟลเดอร์ที่มีสิทธิ์ หากต้องการเปิดหรือปิดข้อกำหนดคีย์ทรัพยากรสำหรับไฟล์ที่มีสิทธิ์ ให้ใช้
set
ดูข้อมูลเพิ่มเติมเกี่ยวกับการอัปเดตความปลอดภัยสำหรับ Google ไดรฟ์
รีเทิร์น
Boolean — Whether the resource key requirement can be applied for the File.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly -
https://www.googleapis.com/auth/drive
get Security Update Enabled()
ระบุว่า File ต้องใช้คีย์ทรัพยากรสำหรับการเข้าถึงเมื่อแชร์โดยใช้ลิงก์หรือไม่ ระบบจะเปิดข้อกำหนดนี้ไว้โดยค่าเริ่มต้นสำหรับไฟล์และโฟลเดอร์ที่มีสิทธิ์
หากต้องการเปิดหรือปิดข้อกำหนดคีย์ทรัพยากรสำหรับไฟล์ที่มีสิทธิ์ ให้ใช้
setSecurityUpdateEnabled
ดูข้อมูลเพิ่มเติมเกี่ยวกับการอัปเดตความปลอดภัยสำหรับ Google ไดรฟ์
รีเทิร์น
Boolean — เปิดใช้ข้อกำหนดของคีย์ทรัพยากรสำหรับ File นี้หรือไม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly -
https://www.googleapis.com/auth/drive
get Sharing Access()
รับข้อมูลว่าผู้ใช้กลุ่มใดบ้างที่เข้าถึง File ได้ นอกเหนือจากผู้ใช้แต่ละรายที่ได้รับสิทธิ์เข้าถึงอย่างชัดเจน
รีเทิร์น
Access — ผู้ใช้กลุ่มใดบ้างที่เข้าถึง File ได้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly -
https://www.googleapis.com/auth/drive
get Sharing Permission()
รับสิทธิ์ที่มอบให้แก่ผู้ใช้ที่เข้าถึง File ได้
นอกเหนือจากผู้ใช้แต่ละรายที่ได้รับสิทธิ์เข้าถึงอย่างชัดเจน
รีเทิร์น
Permission - สิทธิ์ที่มอบให้แก่ผู้ใช้ที่มีสิทธิ์เข้าถึง File
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly -
https://www.googleapis.com/auth/drive
get Size()
รับจำนวนไบต์ที่ใช้จัดเก็บ File ในไดรฟ์ โปรดทราบว่า
ไฟล์แอปพลิเคชัน Google Workspace จะไม่นับรวมในขีดจำกัดพื้นที่เก็บข้อมูลของไดรฟ์ ดังนั้นระบบจะแสดงผลเป็น
0 ไบต์
รีเทิร์น
Integer — จำนวนไบต์ที่ใช้จัดเก็บ File ในไดรฟ์
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly -
https://www.googleapis.com/auth/drive
get Target Id()
หากเป็นทางลัด จะแสดงรหัสของรายการที่ทางลัดชี้ไป
ไม่เช่นนั้นจะแสดงผลเป็น 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 — รหัสสินค้าเป้าหมาย
get Target Mime Type()
หากเป็นทางลัด จะแสดงผลประเภท 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 ของรายการเป้าหมาย
get Target Resource Key()
หากไฟล์เป็นทางลัด ระบบจะแสดงคีย์ทรัพยากรของรายการที่ไฟล์ชี้ไป คีย์แหล่งข้อมูลคือ พารามิเตอร์เพิ่มเติมที่คุณต้องส่งเพื่อเข้าถึงไฟล์ที่แชร์โดยใช้ ลิงก์
หากไฟล์ไม่ใช่ทางลัด ระบบจะแสดงผล 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
get Thumbnail()
รับภาพขนาดย่อของไฟล์ หรือ 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|null — รูปภาพขนาดย่อของไฟล์
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly -
https://www.googleapis.com/auth/drive
get Url()
รับ URL ที่ใช้เปิด File ในแอป Google เช่น
ไดรฟ์หรือเอกสารได้
รีเทิร์น
String - URL ที่ใช้ดู File ในแอป Google เช่น
ไดรฟ์หรือเอกสาร
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly -
https://www.googleapis.com/auth/drive
get Viewers()
รับรายการผู้มีสิทธิ์อ่านและผู้แสดงความคิดเห็นสำหรับ 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 (const viewer of viewers) { console.log(viewer.getEmail()); } }
รีเทิร์น
User[] — หากผู้ใช้มีสิทธิ์แก้ไขสำหรับ File นี้ ระบบจะแสดงรายการ
ผู้ดูและผู้แสดงความคิดเห็น หากผู้ใช้ไม่มีสิทธิ์เข้าถึงระดับแก้ไข ระบบจะแสดงผลเป็นอาร์เรย์เปล่า
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly -
https://www.googleapis.com/auth/drive
is Starred()
is Trashed()
กำหนดว่า File อยู่ในถังขยะของไดรฟ์ของผู้ใช้หรือไม่
รีเทิร์น
Boolean — true หากFileอยู่ในถังขยะของไดรฟ์ของผู้ใช้
false หากไม่อยู่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly -
https://www.googleapis.com/auth/drive
make Copy()
สร้างสำเนาไฟล์
// 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
make Copy(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()); }
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
destination | Folder | ไดเรกทอรีที่จะคัดลอกไฟล์ไปไว้ |
รีเทิร์น
File — สำเนาใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
make Copy(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()); }
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
name | String | ชื่อไฟล์ที่ควรใช้กับสำเนาใหม่ |
รีเทิร์น
File — สำเนาใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
make Copy(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()); }
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
name | String | ชื่อไฟล์ที่ควรใช้กับสำเนาใหม่ |
destination | Folder | ไดเรกทอรีที่จะคัดลอกไฟล์ไปไว้ |
รีเทิร์น
File — สำเนาใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
move To(destination)
ย้ายรายการนี้ไปยังโฟลเดอร์ปลายทางที่ระบุ
ผู้ใช้ปัจจุบันต้องเป็นเจ้าของไฟล์หรือมีสิทธิ์เข้าถึงระดับแก้ไขอย่างน้อยในโฟลเดอร์หลักปัจจุบันของรายการเพื่อย้ายรายการไปยังโฟลเดอร์ปลายทาง
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
destination | Folder | โฟลเดอร์ที่จะกลายเป็นโฟลเดอร์หลักใหม่ |
รีเทิร์น
File — This File, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
remove Commenter(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'); }
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
email | String | อีเมลของผู้ใช้ที่จะนำออก |
รีเทิร์น
File — This File, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
remove Commenter(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())); }
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
user | User | การแสดงผู้ใช้ที่จะนำออก |
รีเทิร์น
File — This File, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
remove Editor(emailAddress)
นำผู้ใช้ที่ระบุออกจากรายชื่อผู้แก้ไขสำหรับ File วิธีนี้จะไม่
บล็อกผู้ใช้ไม่ให้เข้าถึง File หากผู้ใช้เป็นสมาชิกของกลุ่มผู้ใช้ที่มี
สิทธิ์เข้าถึงทั่วไป เช่น หากมีการแชร์ File กับทั้งโดเมนของผู้ใช้ หรือหาก File อยู่ในไดรฟ์ที่แชร์ซึ่งผู้ใช้เข้าถึงได้
สำหรับไฟล์ในไดรฟ์ การดำเนินการนี้จะนำผู้ใช้ดังกล่าวออกจากรายชื่อผู้ดูด้วย
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
email | String | อีเมลของผู้ใช้ที่จะนำออก |
รีเทิร์น
File — This File, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
remove Editor(user)
นำผู้ใช้ที่ระบุออกจากรายชื่อผู้แก้ไขสำหรับ File วิธีนี้จะไม่
บล็อกผู้ใช้ไม่ให้เข้าถึง File หากผู้ใช้เป็นสมาชิกของกลุ่มผู้ใช้ที่มี
สิทธิ์เข้าถึงทั่วไป เช่น หากมีการแชร์ File กับทั้งโดเมนของผู้ใช้ หรือหาก File อยู่ในไดรฟ์ที่แชร์ซึ่งผู้ใช้เข้าถึงได้
สำหรับไฟล์ในไดรฟ์ การดำเนินการนี้จะนำผู้ใช้ดังกล่าวออกจากรายชื่อผู้ดูด้วย
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
user | User | การแสดงผู้ใช้ที่จะนำออก |
รีเทิร์น
File — This File, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
remove Viewer(emailAddress)
นำผู้ใช้ที่ระบุออกจากรายชื่อผู้ชมและผู้แสดงความคิดเห็นสำหรับFile วิธีนี้จะไม่มีผลหากผู้ใช้เป็นเอดิเตอร์ ไม่ใช่ผู้ดูหรือผู้แสดงความคิดเห็น นอกจากนี้ วิธีนี้ยัง
ไม่ได้บล็อกไม่ให้ผู้ใช้เข้าถึง File หากผู้ใช้เป็นสมาชิกของกลุ่มผู้ใช้ที่มี
สิทธิ์เข้าถึงทั่วไป เช่น หากมีการแชร์ File กับโดเมนทั้งหมดของผู้ใช้ หรือหาก File อยู่ในไดรฟ์ที่แชร์ซึ่งผู้ใช้เข้าถึงได้
สำหรับไฟล์ในไดรฟ์ การดำเนินการนี้จะนำผู้ใช้ดังกล่าวออกจากรายชื่อผู้แก้ไขด้วย
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
email | String | อีเมลของผู้ใช้ที่จะนำออก |
รีเทิร์น
File — This File for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
remove Viewer(user)
นำผู้ใช้ที่ระบุออกจากรายชื่อผู้ชมและผู้แสดงความคิดเห็นสำหรับFile วิธีนี้จะไม่มีผลหากผู้ใช้เป็นผู้แก้ไข ไม่ใช่ผู้ดู นอกจากนี้ วิธีนี้ยังไม่บล็อกไม่ให้ผู้ใช้เข้าถึง File หากผู้ใช้เป็นสมาชิกในกลุ่มผู้ใช้ที่มีสิทธิ์เข้าถึงทั่วไป เช่น หากมีการแชร์ File กับทั้งโดเมนของผู้ใช้ หรือหาก File อยู่ในไดรฟ์ที่แชร์ซึ่งผู้ใช้เข้าถึงได้
สำหรับไฟล์ในไดรฟ์ การดำเนินการนี้จะนำผู้ใช้ดังกล่าวออกจากรายชื่อผู้แก้ไขด้วย
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
user | User | การแสดงผู้ใช้ที่จะนำออก |
รีเทิร์น
File — This File for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
revoke Permissions(emailAddress)
เพิกถอนสิทธิ์เข้าถึง File ที่ให้แก่ผู้ใช้ที่ระบุ วิธีนี้จะไม่
บล็อกผู้ใช้ไม่ให้เข้าถึง File หากผู้ใช้เป็นสมาชิกของกลุ่มผู้ใช้ที่มี
สิทธิ์เข้าถึงทั่วไป เช่น หากมีการแชร์ File กับโดเมนทั้งหมด
ของผู้ใช้
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
email | String | อีเมลของผู้ใช้ที่ควรเพิกถอนสิทธิ์เข้าถึง |
รีเทิร์น
File — This File, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
revoke Permissions(user)
เพิกถอนสิทธิ์เข้าถึง File ที่ให้แก่ผู้ใช้ที่ระบุ วิธีนี้จะไม่
บล็อกผู้ใช้ไม่ให้เข้าถึง File หากผู้ใช้เป็นสมาชิกของกลุ่มผู้ใช้ที่มี
สิทธิ์เข้าถึงทั่วไป เช่น หากมีการแชร์ File กับโดเมนทั้งหมด
ของผู้ใช้
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
user | User | การแสดงผู้ใช้ที่ควรเพิกถอนสิทธิ์เข้าถึง |
รีเทิร์น
File — This File, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
set Content(content)
เขียนทับเนื้อหาของไฟล์ด้วยการแทนที่ที่ระบุ แสดงข้อยกเว้นหาก content มีขนาดใหญ่กว่า 10 MB
// Creates a text file with the content 'Hello, world!' const 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());
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
content | String | เนื้อหาใหม่ของไฟล์ |
รีเทิร์น
File — This File, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
set Description(description)
set Name(name)
set Owner(emailAddress)
เปลี่ยนเจ้าของ File นอกจากนี้ เมธอดนี้ยังให้สิทธิ์เข้าถึงระดับแก้ไขที่ชัดเจนแก่เจ้าของเดิม
ใน File ด้วย
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
email | String | อีเมลของผู้ใช้ที่ควรเป็นเจ้าของใหม่ |
รีเทิร์น
File — File นี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
set Owner(user)
เปลี่ยนเจ้าของ File นอกจากนี้ เมธอดนี้ยังให้สิทธิ์เข้าถึงระดับแก้ไขที่ชัดเจนแก่เจ้าของเดิม
ใน File ด้วย
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
user | User | การแสดงผู้ใช้ที่ควรเป็นเจ้าของใหม่ |
รีเทิร์น
File — File นี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
set Security Update Enabled(enabled)
กำหนดว่า File ต้องใช้คีย์ทรัพยากรสำหรับการเข้าถึงหรือไม่เมื่อมีการแชร์โดยใช้ลิงก์ ระบบจะเปิดใช้ไฟล์และโฟลเดอร์ที่มีสิทธิ์โดยค่าเริ่มต้น
ดูข้อมูลเพิ่มเติมเกี่ยวกับการอัปเดตความปลอดภัยสำหรับ Google ไดรฟ์
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
enabled | Boolean | เลือกว่าจะเปิดใช้ข้อกำหนดคีย์ทรัพยากรสำหรับ File หรือไม่ |
รีเทิร์น
File — This File, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
set Sharing(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.) const folder = DriveApp.createFolder('Shared Folder'); folder.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.EDIT);
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
access | Access | ผู้ใช้กลุ่มใดควรมีสิทธิ์เข้าถึง File |
permission | Permission | สิทธิ์ที่ควรให้แก่ผู้ใช้ที่เข้าถึง File ได้ |
รีเทิร์น
File — File นี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
set Starred(starred)
กำหนดว่า File จะติดดาวในไดรฟ์ของผู้ใช้หรือไม่ ค่าเริ่มต้นสำหรับ File ใหม่คือ false
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
starred | Boolean | true หากต้องการให้Fileติดดาวใน
ไดรฟ์ของผู้ใช้ false หากไม่ต้องการ |
รีเทิร์น
File — File นี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
set Trashed(trashed)
กำหนดว่า File อยู่ในถังขยะของไดรฟ์ของผู้ใช้หรือไม่ มีเพียงเจ้าของเท่านั้นที่ทิ้ง File ได้ ค่าเริ่มต้นสำหรับ File ใหม่คือ false
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
trashed | Boolean | true หากต้องการย้าย File ไปยังถังขยะของ
ไดรฟ์ของผู้ใช้ false หากไม่ต้องการ |
รีเทิร์น
File — File นี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive