Aynı komut dosyalarını Rhino'dan V8'e toplu olarak taşıma

Bu sayfada, Apps Komut Dosyası ve Apps Komut Dosyası API'sini kullanarak aynı komut dosyalarını V8'e nasıl taşıyacağınız açıklanmaktadır.

Rhino çalışma zamanını kullanan tüm komut dosyalarını, 31 Ocak 2026 itibarıyla kullanımdan kaldırılacak olan Rhino'dan önce taşımanız gerekir. Rhino'da çalışan birden fazla özdeş komut dosyanız varsa Apps Script API'yi kullanarak bunları V8'e birlikte taşıyabilirsiniz.

Ortamınızı ayarlama

  1. Apps Komut Dosyası kontrol paneli ayarlarından Apps Komut Dosyası API'sini etkinleştirin.
    1. Apps Komut Dosyası kontrol paneli ayarlarına gidin.
    2. API devre dışıysa Google Apps Script API'yi tıklayın ve Google Apps Script API açma/kapatma düğmesini etkinleştirin.
  2. Standart bir Google Cloud projesi oluşturun veya mevcut bir projeyi yeniden kullanın.
  3. Cloud projenizde OAuth kullanıcı rızası ekranını yapılandırın.
  4. Cloud projenizde Apps Script API'yi etkinleştirin.

    Apps Script API'yi etkinleştirme

  5. Bir Apps Komut Dosyası projesi oluşturun ve Apps Komut Dosyası projesini Cloud projenize atayın.

    1. Apps Komut Dosyası kontrol panelinden veya script.new adresine giderek bağımsız bir Apps Komut Dosyası projesi oluşturun.
    2. Proje Ayarları'nı Proje ayarları simgesi tıklayın.
    3. Google Cloud Platform (GCP) Projesi bölümünde Projeyi değiştir'i tıklayın.
    4. Cloud projenizin proje numarasını girin.
    5. Projeyi ayarla'yı tıklayın.

Komut dosyalarını taşıma

Aşağıdaki kod örneğinde, her Apps Komut Dosyası projesindeki dosyaları V8 ile uyumlu bir dosya grubuyla değiştirerek Apps Komut Dosyası API'si ile aynı komut dosyalarını Rhino'dan V8'e taşıma işlemi gösterilmektedir.

Taşımayı planladığınız komut dosyası projelerinde en az düzenleyici erişiminizin olduğundan emin olun.

Code.gs

function updateRhinoScripts() {
  // An array of script IDs of script projects to migrate.
  // TODO(developer): Replace with your script IDs.
  const scriptIds = ['abcdef12345678', 'abcdef12345678'];
  // An array of file objects to replace the existing files in each script project.
  // Remember to include all files for the script, excluded files are deleted.
  // TODO(developer): Replace with your script files.
  const filesToUpdate = {
    "files": [
      {
        "name": "Code",
        "type": "SERVER_JS",
        "source": "// New updates\nfunction myFunction() {\n  console.log('Hello, world!');\n}"
      },
      {
        "name": "appsscript",
        "type": "JSON",
        "source": JSON.stringify({
          "timeZone": "America/New_York",
          "dependencies": {},
          "exceptionLogging": "STACKDRIVER",
          "runtimeVersion": "V8"
        })
      }
    ]
  };
  updateMultipleAppsScripts(scriptIds, filesToUpdate);
}

function updateMultipleAppsScripts(scriptIds, filesToUpdate) {
  // 'scriptIds' should be an array of script IDs
  // 'filesToUpdate' should be an array of objects, each with:
  // name: The filename (For example, "Code", "Utilities")
  // source: The source code for that file.
  scriptIds.forEach(function (scriptId) {
    // Makes the API request.
    const response = UrlFetchApp.fetch(
      `https://script.googleapis.com/v1/projects/${scriptId}/content`,
      {
        method: "PUT",
        headers: {
          Authorization: `Bearer ${ScriptApp.getOAuthToken()}`
        },
        contentType: "application/json",
        payload: JSON.stringify(filesToUpdate),
        muteHttpExceptions: true
      }
    );
    if (response.getResponseCode() !== 200) {
      console.log(`Error updating script ${scriptId}: ${response.getContentText()}`);
    } else {
      console.log(`Script ${scriptId} updated successfully!`);
    }
  });
}

appsscript.json

Apps Script projenizde Apps Script API'yi kullanmak için aşağıdaki OAuth kapsamlarını manifest dosyanıza eklemeniz gerekir:

  • "https://www.googleapis.com/auth/script.projects"
  • "https://www.googleapis.com/auth/script.external_request"

Manifest dosyasını düzenleyicide göstermek için Proje Ayarları'nı tıklayın Proje ayarları simgesi ve "appsscript.json" manifest dosyasını düzenleyicide göster kutusunu işaretleyin. Aşağıda, uygun OAuth kapsamlarını içeren örnek bir manifest dosyası verilmiştir:

{
  "timeZone": "America/Denver",
  "dependencies": {
  },
  "oauthScopes": [
  "https://www.googleapis.com/auth/script.projects",
  "https://www.googleapis.com/auth/script.external_request"
],
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8"
}