Google Apps Komut Dosyası API'si, uygulamanızdan Google Apps Komut Dosyası projeleri oluşturmanıza ve değiştirmenize olanak tanır. Bu sayfadaki örneklerde, API ile yaygın proje yönetimi işlemlerinin nasıl gerçekleştirilebileceği gösterilmektedir.
API'yi kullanmak için önce etkinleştirmeniz gerekir.
Bu örneklerde, komut dosyası proje kimliğini nerede sağlayacağınızı belirtmek için scriptId yer tutucuları kullanılır. Komut dosyası kimliğini bulmak için aşağıdaki adımları uygulayın:
- Apps Komut Dosyası projesinde, sol üstte Proje Ayarları'nı tıklayın.
- "Komut dosyası kimliği"nin yanındaki Kopyala'yı tıklayın.
Yeni bir Apps Komut Dosyası projesi oluşturma
Aşağıdaki projects.create isteği yeni bir bağımsız komut dosyası oluşturur.
POST https://scriptmanagement.googleapis.com/v1/projects/
{
"title": "My Script"
}Proje meta verilerini alma
Aşağıdaki projects.get isteği, komut dosyası projesinin meta verilerini alır.
GET https://scriptmanagement.googleapis.com/v1/projects/scriptId
Yanıt, aşağıdaki gibi bir nesneden oluşur:
{
"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" },
}Proje dosyalarını alma
Aşağıdaki projects.getContent isteği, her senaryo dosyası için kod kaynağı ve meta veriler de dahil olmak üzere senaryo projesinin içeriğini alır.
GET https://scriptmanagement.googleapis.com/v1/projects/scriptId/content
Yanıt, aşağıdaki gibi bir Content nesnesinden oluşur:
{ "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" }] }
Proje dosyalarını güncelleme
Aşağıdaki projects.updateContent isteği, belirtilen komut dosyası projesinin içeriğini günceller. Bu içerik, HEAD sürümü olarak depolanır ve komut dosyası API yürütülebilir projesi olarak yürütüldüğünde kullanılır.
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" }] }
Yanıt, aşağıdaki gibi bir Content nesnesinden oluşur:
{ "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" }] }