Halaman ini menjelaskan cara memigrasikan skrip yang identik ke V8 menggunakan Google Apps Script dan Apps Script API.
Runtime Rhino ditolak mulai 31 Januari 2026. Migrasikan skrip apa pun yang menggunakan runtime Rhino sebelum tanggal tersebut. Jika Anda memiliki beberapa skrip identik yang berjalan di Rhino, migrasikan semuanya ke V8 menggunakan Apps Script API.
Menyiapkan lingkungan Anda
- Dari setelan dasbor Apps Script, aktifkan
Apps Script API.
- Buka setelan dasbor Apps Script.
- Jika API dinonaktifkan, klik Apps Script API, lalu aktifkan tombol Apps Script API.
- Buat project Google Cloud standar atau gunakan kembali project yang sudah ada.
- Di project Cloud Anda, konfigurasi layar izin OAuth.
Di project Cloud Anda, aktifkan Apps Script API.
Buat project Apps Script dan tetapkan ke project Cloud Anda.
- Buat project Apps Script mandiri dari dasbor Apps Script atau dengan membuka script.new.
- Klik Setelan Project
.
- Di bagian Google Cloud Project, klik Change project.
- Masukkan nomor project project Cloud Anda.
- Klik Set project.
Skrip migrasi
Contoh kode berikut menunjukkan cara menggunakan Apps Script API untuk memigrasikan skrip yang identik dari Rhino ke V8 dengan mengganti file di setiap project Apps Script dengan sekumpulan file yang kompatibel dengan V8.
Saat Anda menggunakan metode
projects.UpdateContent
Apps Script API, sertakan semua file dalam project
skrip, bahkan file yang tidak ingin Anda ubah. Jika Anda tidak menyertakan file, file akan dihapus dan tidak dapat dipulihkan.
Pastikan Anda memiliki akses editor ke project skrip yang ingin Anda migrasikan.
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
Untuk menggunakan Apps Script API di project Apps Script, tambahkan cakupan OAuth berikut ke file manifes Anda:
"https://www.googleapis.com/auth/script.projects""https://www.googleapis.com/auth/script.external_request"
Untuk menampilkan file manifes di editor, klik Project Settings
dan centang kotak Show "appsscript.json" manifest file in editor. Berikut
adalah contoh file manifes dengan cakupan OAuth yang sesuai:
{
"timeZone": "America/Denver",
"dependencies": {
},
"oauthScopes": [
"https://www.googleapis.com/auth/script.projects",
"https://www.googleapis.com/auth/script.external_request"
],
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8"
}