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

Bu sayfada, Google Apps Komut Dosyası ve Apps Komut Dosyası API'si kullanılarak aynı komut dosyalarının V8'e nasıl taşınacağı açıklanmaktadır.

Rhino çalışma zamanı, 31 Ocak 2026 itibarıyla devre dışı bırakıldı. Bu tarihten önce Rhino çalışma zamanını kullanan tüm komut dosyalarını taşıyın. Rhino'da çalışan birden fazla özdeş komut dosyanız varsa bunları Apps Komut Dosyası API'sini kullanarak V8'e birlikte taşıyın.

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 Apps Komut Dosyası API'yi tıklayın, ardından Apps Komut Dosyası 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 Komut Dosyası API'sini etkinleştirin.

    Apps Komut Dosyası API'sini etkinleştirme

  5. Apps Komut Dosyası projesi oluşturun ve bunu 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 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.

Apps Komut Dosyası API'sinin projects.UpdateContent yöntemini kullanırken komut dosyası projesindeki tüm dosyaları (değiştirmek istemediğiniz dosyalar dahil) ekleyin. Dosya eklemezseniz dosya silinir ve geri yüklenemez.

Taşımayı planladığınız komut dosyası projelerinde en az düzenleyici erişiminiz 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 Komut Dosyası projenizde Apps Komut Dosyası API'sini kullanmak için aşağıdaki OAuth kapsamlarını manifesto dosyanıza ekleyin:

  • "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"
}