توضّح هذه الصفحة كيفية نقل النصوص البرمجية المتطابقة إلى V8 باستخدام "برمجة تطبيقات Google" وApps Script API.
تم إيقاف وقت تشغيل Rhino نهائيًا في 31 يناير 2026 أو بعده. يُرجى نقل أي نصوص برمجية تستخدم وقت تشغيل Rhino قبل هذا التاريخ. إذا كانت لديك نصوص برمجية متطابقة متعددة تعمل على Rhino، يمكنك نقلها إلى V8 دفعةً واحدة باستخدام Apps Script API.
إعداد البيئة
- من إعدادات لوحة بيانات "برمجة تطبيقات Google"، فعِّل Apps Script API.
- انتقِل إلى إعدادات لوحة بيانات "برمجة تطبيقات Google".
- إذا كانت واجهة برمجة التطبيقات غير مفعّلة، انقر على Apps Script API، ثم فعِّل مفتاح Apps Script API.
- أنشِئ مشروعًا عاديًا على Google Cloud أو أعِد استخدام مشروع حالي.
- في مشروع على السحابة الإلكترونية، اضبط شاشة طلب الموافقة المتعلّقة ببروتوكول OAuth.
في مشروعك على السحابة الإلكترونية، فعِّل Apps Script API.
أنشِئ مشروعًا في "برمجة تطبيقات Google" واربطه بمشروع على السحابة الإلكترونية.
- أنشِئ مشروعًا مستقلاً في "برمجة تطبيقات Google" من لوحة بيانات "برمجة تطبيقات Google" أو من خلال الانتقال إلى script.new.
- انقر على إعدادات المشروع
.
- في قسم مشروع Google Cloud ، انقر على تغيير المشروع.
- أدخِل رقم مشروع على السحابة الإلكترونية.
- انقر على ضبط المشروع.
نقل النصوص البرمجية
يوضّح نموذج الرمز البرمجي التالي كيفية استخدام Apps Script API لنقل النصوص البرمجية المتطابقة من Rhino إلى V8 من خلال استبدال الملفات في كل مشروع من مشاريع برمجة تطبيقات Google بمجموعة من الملفات المتوافقة مع V8.
عند استخدام طريقة
projects.UpdateContent
في برمجة تطبيقات API، عليك تضمين جميع الملفات في مشروع النص البرمجي
، حتى الملفات التي لا تريد تغييرها. إذا لم تضمِّن ملفًا، سيتم حذفه ولا يمكن استعادته.
تأكَّد من أنّه لديك إذن الوصول إلى مشاريع النصوص البرمجية التي تخطط لنقلها كمحرِّر على الأقل.
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 API في مشروع "برمجة تطبيقات Google"، أضِف نطاقات OAuth التالية إلى ملف البيان:
"https://www.googleapis.com/auth/script.projects""https://www.googleapis.com/auth/script.external_request"
لعرض ملف البيان في المحرّر، انقر على إعدادات المشروع
وضَع علامة في مربّع عرض ملف البيان "appscript.json" في المحرّر. في ما يلي نموذج لملف بيان يتضمّن نطاقات OAuth المناسبة:
{
"timeZone": "America/Denver",
"dependencies": {
},
"oauthScopes": [
"https://www.googleapis.com/auth/script.projects",
"https://www.googleapis.com/auth/script.external_request"
],
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8"
}