خدمة Drive المتقدّمة
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
تتيح لك خدمة Drive المتقدّمة استخدام
Google Drive API في "برمجة تطبيقات Google". تمامًا مثل خدمة Drive المضمّنة في Apps Script، تتيح واجهة برمجة التطبيقات هذه للبرامج النصية إنشاء الملفات والمجلدات والعثور عليها وتعديلها في Google Drive. في معظم الحالات، تكون الخدمة المضمّنة أسهل في الاستخدام، ولكن هذه الخدمة المتقدّمة توفّر بعض الميزات الإضافية، بما في ذلك إمكانية الوصول إلى خصائص الملفات المخصّصة بالإضافة إلى مراجعات الملفات والمجلدات.
مراجع
للحصول على معلومات مفصّلة حول هذه الخدمة، يُرجى الاطّلاع على المستندات المرجعية الخاصة بواجهة Google Drive API. وكما هو الحال مع جميع الخدمات المتقدّمة في "برمجة التطبيقات"، تستخدم خدمة Drive المتقدّمة الكائنات والطرق والمَعلمات نفسها التي تستخدمها واجهة برمجة التطبيقات العامة. لمزيد من المعلومات، يُرجى الاطّلاع على كيفية تحديد تواقيع الطرق.
للإبلاغ عن مشاكل والعثور على معلومات دعم أخرى، يُرجى الاطّلاع على دليل دعم Drive API.
نموذج التعليمات البرمجية
تستخدم عيّنات الرموز البرمجية في هذا القسم الإصدار 3 من واجهة برمجة التطبيقات.
تحميل ملفات
يوضّح نموذج الرمز البرمجي التالي كيفية حفظ ملف في
Drive الخاص بالمستخدم.
سرد المجلدات
يوضّح نموذج الرمز البرمجي التالي كيفية إدراج المجلدات ذات المستوى الأعلى في حساب Drive الخاص بالمستخدم. يُرجى العِلم أنّه يتم استخدام رموز مميزة للصفحات للوصول إلى القائمة الكاملة بالنتائج.
مراجعات القائمة
يوضّح نموذج الرمز البرمجي التالي كيفية إدراج المراجعات لملف معيّن. يُرجى العِلم أنّ بعض الملفات يمكن أن تتضمّن عدة مراجعات، وعليك استخدام رموز الصفحات للوصول إلى القائمة الكاملة للنتائج.
إضافة خصائص الملف
يستخدم نموذج الرمز البرمجي التالي الحقل appProperties
لإضافة سمة مخصّصة إلى ملف. لا تظهر السمة المخصّصة إلا للنص البرمجي. لإضافة خاصية مخصّصة إلى الملف يمكن للتطبيقات الأخرى الاطّلاع عليها أيضًا، استخدِم الحقل properties
بدلاً من ذلك. لمزيد من المعلومات، يُرجى الاطّلاع على إضافة خصائص ملفات مخصّصة.
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eThe advanced Drive service in Apps Script provides more features than the built-in service, like access to custom file properties and revisions.\u003c/p\u003e\n"],["\u003cp\u003eThis advanced service requires enabling before use and mirrors the functionality of the Google Drive API.\u003c/p\u003e\n"],["\u003cp\u003eCode samples demonstrate how to upload files, list folders and revisions, and add custom properties to files in Google Drive using this service.\u003c/p\u003e\n"],["\u003cp\u003eThe provided samples utilize version 3 of the Google Drive API and illustrate common Drive operations within Apps Script.\u003c/p\u003e\n"],["\u003cp\u003eFor comprehensive details, refer to the Google Drive API reference documentation and support guide.\u003c/p\u003e\n"]]],[],null,["# Advanced Drive Service\n\nThe advanced Drive service lets you use the\n[Google Drive API](/drive/web) in Apps Script. Much like\nApps Script's [built-in Drive\nservice](/apps-script/reference/drive), this API allows scripts to create, find,\nand modify files and folders in Google Drive. In most cases, the built-in\nservice is easier to use, but this advanced service provides a few extra\nfeatures, including access to custom file properties as well as revisions for\nfiles and folders.\n| **Note:** This is an advanced service that must be [enabled before\n| use](/apps-script/guides/services/advanced#enable_advanced_services).\n\nReference\n---------\n\nFor detailed information on this service, see the [reference\ndocumentation](/drive/api/reference/rest/v3) for the Google Drive API. Like all\nadvanced services in Apps Script, the advanced\nDrive service uses the same objects, methods, and parameters as\nthe public API. For more information, see [How method signatures are\ndetermined](/apps-script/guides/services/advanced#how_method_signatures_are_determined).\n\nTo report issues and find other support, see the [Drive API support\nguide](/drive/api/support).\n\nSample code\n-----------\n\nThe code samples in this section use [version 3](/drive/api/reference/rest/v3)\nof the API.\n\n### Upload files\n\nThe following code sample shows how to save a file to a user's\nDrive. \nadvanced/drive.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/drive.gs) \n\n```javascript\n/**\n * Uploads a new file to the user's Drive.\n */\nfunction uploadFile() {\n try {\n // Makes a request to fetch a URL.\n const image = UrlFetchApp.fetch('http://goo.gl/nd7zjB').getBlob();\n let file = {\n name: 'google_logo.png',\n mimeType: 'image/png'\n };\n // Create a file in the user's Drive.\n file = Drive.Files.create(file, image, {'fields': 'id,size'});\n console.log('ID: %s, File size (bytes): %s', file.id, file.size);\n } catch (err) {\n // TODO (developer) - Handle exception\n console.log('Failed to upload file with error %s', err.message);\n }\n}\n```\n\n### List folders\n\nThe following code sample shows how to list the top-level folders in the user's\nDrive. Note the use of page tokens to access the full list of\nresults. \nadvanced/drive.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/drive.gs) \n\n```javascript\n/**\n * Lists the top-level folders in the user's Drive.\n */\nfunction listRootFolders() {\n const query = '\"root\" in parents and trashed = false and ' +\n 'mimeType = \"application/vnd.google-apps.folder\"';\n let folders;\n let pageToken = null;\n do {\n try {\n folders = Drive.Files.list({\n q: query,\n pageSize: 100,\n pageToken: pageToken\n });\n if (!folders.files || folders.files.length === 0) {\n console.log('All folders found.');\n return;\n }\n for (let i = 0; i \u003c folders.files.length; i++) {\n const folder = folders.files[i];\n console.log('%s (ID: %s)', folder.name, folder.id);\n }\n pageToken = folders.nextPageToken;\n } catch (err) {\n // TODO (developer) - Handle exception\n console.log('Failed with error %s', err.message);\n }\n } while (pageToken);\n}\n```\n\n### List revisions\n\nThe following code sample shows how to list the revisions for a given file. Note\nthat some files can have several revisions and you should use page tokens to\naccess the full list of results. \nadvanced/drive.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/drive.gs) \n\n```javascript\n/**\n * Lists the revisions of a given file.\n * @param {string} fileId The ID of the file to list revisions for.\n */\nfunction listRevisions(fileId) {\n let revisions;\n const pageToken = null;\n do {\n try {\n revisions = Drive.Revisions.list(\n fileId,\n {'fields': 'revisions(modifiedTime,size),nextPageToken'});\n if (!revisions.revisions || revisions.revisions.length === 0) {\n console.log('All revisions found.');\n return;\n }\n for (let i = 0; i \u003c revisions.revisions.length; i++) {\n const revision = revisions.revisions[i];\n const date = new Date(revision.modifiedTime);\n console.log('Date: %s, File size (bytes): %s', date.toLocaleString(),\n revision.size);\n }\n pageToken = revisions.nextPageToken;\n } catch (err) {\n // TODO (developer) - Handle exception\n console.log('Failed with error %s', err.message);\n }\n } while (pageToken);\n}\n```\n\n### Add file properties\n\nThe following code sample uses the `appProperties` field to add a custom\nproperty to a file. The custom property is only visible to the script. To add a\ncustom property to the file that's also visible to other apps, use the\n`properties` field, instead. For more information, see [Add custom file\nproperties](/drive/api/guides/properties). \nadvanced/drive.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/drive.gs) \n\n```javascript\n/**\n * Adds a custom app property to a file. Unlike Apps Script's DocumentProperties,\n * Drive's custom file properties can be accessed outside of Apps Script and\n * by other applications; however, appProperties are only visible to the script.\n * @param {string} fileId The ID of the file to add the app property to.\n */\nfunction addAppProperty(fileId) {\n try {\n let file = {\n 'appProperties': {\n 'department': 'Sales'\n }\n };\n // Updates a file to add an app property.\n file = Drive.Files.update(file, fileId, null, {'fields': 'id,appProperties'});\n console.log(\n 'ID: %s, appProperties: %s',\n file.id,\n JSON.stringify(file.appProperties, null, 2));\n } catch (err) {\n // TODO (developer) - Handle exception\n console.log('Failed with error %s', err.message);\n }\n}\n```"]]