Apps Script API ช่วยให้คุณสร้างและแก้ไขโปรเจ็กต์ Apps Script จากแอปของคุณได้ ตัวอย่างในหน้านี้จะแสดงวิธีดำเนินการจัดการโปรเจ็กต์ทั่วไปด้วย API
หมายเหตุ: ต้องเปิดใช้ Apps Script API ก่อนใช้งาน
ในตัวอย่างเหล่านี้ ตัวยึดตำแหน่ง scriptId จะใช้เพื่อระบุตําแหน่งที่คุณจะระบุรหัสโปรเจ็กต์สคริปต์ ทำตามขั้นตอนด้านล่างเพื่อค้นหารหัสสคริปต์
- ในโปรเจ็กต์ Apps Script ให้คลิกการตั้งค่าโปรเจ็กต์ที่ด้านซ้ายบน
- คลิกคัดลอกข้าง "รหัสสคริปต์"
สร้างโปรเจ็กต์ Apps Script ใหม่
คำขอ projects.create ต่อไปนี้จะสร้างสคริปต์แบบสแตนด์อโลนใหม่
POST https://scriptmanagement.googleapis.com/v1/projects/
{ "title": "My Script" }
เรียกข้อมูลข้อมูลเมตาของโปรเจ็กต์
คำขอ projects.get ต่อไปนี้ได้รับข้อมูลเมตาของโปรเจ็กต์สคริปต์
GET https://scriptmanagement.googleapis.com/v1/projects/scriptId
การตอบสนองประกอบด้วยออบเจ็กต์ ดังเช่นตัวอย่างนี้
{ "scriptId": "scriptId", "title": "My Title", "parentId": "parentId", "createTime": "2017-10-02T15:01:23.045123456Z", "updateTime": "2017-10-02T15:01:23.045123456Z", "creator": { "name": "Grant" }, "lastModifyUser": { "name": "Grant" }, }
เรียกข้อมูลไฟล์โครงการ
คำขอ projects.getContent ต่อไปนี้จะได้รับเนื้อหาของโปรเจ็กต์สคริปต์ รวมถึงแหล่งที่มาของโค้ดและข้อมูลเมตาสำหรับไฟล์สคริปต์แต่ละไฟล์
GET https://scriptmanagement.googleapis.com/v1/projects/scriptId/content
การตอบสนองประกอบด้วยออบเจ็กต์ Content ดังเช่นตัวอย่างนี้
{ "scriptId": "scriptId", "files": [{ "name": "My Script", "type": "SERVER_JS", "source": "function hello(){\nconsole.log('Hello world');}", "lastModifyUser": { "name": "Grant", "email": "grant@example.com", }, "createTime": "2017-10-02T15:01:23.045123456Z", "updateTime": "2017-10-02T15:01:23.045123456Z", "functionSet": { "values": [ "name": "helloWorld" ] } }, { "name": "appsscript", "type": "JSON", "source": "{\"timeZone\":\"America/New_York\",\"exceptionLogging\":\"CLOUD\"}", "lastModifyUser": { "name": "Grant", "email": "grant@example.com", }, "createTime": "2017-10-02T15:01:23.045123456Z", "updateTime": "2017-10-02T15:01:23.045123456Z" }] }
อัปเดตไฟล์โครงการ
คำขอ projects.updateContent ต่อไปนี้อัปเดตเนื้อหาโปรเจ็กต์สคริปต์ที่ระบุ เนื้อหานี้จัดเก็บเป็นเวอร์ชัน HEAD และจะใช้เมื่อเรียกใช้สคริปต์เป็นโปรเจ็กต์ที่ดำเนินการได้ของ API
PUT https://scriptmanagement.googleapis.com/v1/projects/scriptID/content
{ "files": [{ "name": "index", "type": "HTML", "source": "<html> <header><title>HTML Page</title></header> <body> My HTML </body> </html>" }, { "name": "My Script", "type": "SERVER_JS", "source": "function hello(){\nconsole.log('Hello world');}", }, { "name": "appsscript", "type": "JSON", "source": "{\"timeZone\":\"America/New_York\",\"exceptionLogging\":\"CLOUD\"}", "lastModifyUser": { "name": "Grant", "email": "grant@example.com", }, "createTime": "2017-10-02T15:01:23.045123456Z", "updateTime": "2017-10-02T15:01:23.045123456Z" }] }
การตอบสนองประกอบด้วยออบเจ็กต์ Content ดังเช่นตัวอย่างนี้
{ "scriptId": "scriptId", "files": [{ "name": "index", "type": "HTML", "source": "<html> <header><title>HTML Page</title></header> <body> My HTML </body> </html>", "lastModifyUser": { "name": "Grant", "email": "grant@example.com", }, "createTime": "2017-10-02T15:01:23.045123456Z", "updateTime": "2017-10-02T15:01:23.045123456Z" }, { "name": "My Script", "type": "SERVER_JS", "source": "function hello(){\nconsole.log('Hello world');}", "lastModifyUser": { "name": "Grant", "email": "grant@example.com", }, "createTime": "2017-10-02T15:01:23.045123456Z", "updateTime": "2017-10-02T15:01:23.045123456Z", "functionSet": { "values": [ "name": "helloWorld" ] } }, { "name": "appsscript", "type": "JSON", "source": "{\"timeZone\":\"America/New_York\",\"exceptionLogging\":\"CLOUD\"}", "lastModifyUser": { "name": "Grant", "email": "grant@example.com", }, "createTime": "2017-10-02T15:01:23.045123456Z", "updateTime": "2017-10-02T15:01:23.045123456Z" }] }