تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
تتيح لك خدمة Drive المتقدّمة استخدام
Google Drive API في "برمجة تطبيقات Google". تمامًا مثل خدمة Drive المضمّنة في Apps Script، تتيح واجهة برمجة التطبيقات هذه للبرامج النصية إنشاء الملفات والمجلدات والعثور عليها وتعديلها في Google Drive. في معظم الحالات، تكون الخدمة المضمّنة أسهل في الاستخدام، ولكن هذه الخدمة المتقدّمة توفّر بعض الميزات الإضافية، بما في ذلك إمكانية الوصول إلى خصائص الملفات المخصّصة بالإضافة إلى مراجعات الملفات والمجلدات.
مراجع
للحصول على معلومات مفصّلة حول هذه الخدمة، يُرجى الاطّلاع على المستندات المرجعية الخاصة بواجهة Google Drive API. وكما هو الحال مع جميع الخدمات المتقدّمة في "برمجة التطبيقات"، تستخدم خدمة Drive المتقدّمة الكائنات والطرق والمَعلمات نفسها التي تستخدمها واجهة برمجة التطبيقات العامة. لمزيد من المعلومات، يُرجى الاطّلاع على كيفية تحديد تواقيع الطرق.
للإبلاغ عن مشاكل والعثور على معلومات دعم أخرى، يُرجى الاطّلاع على دليل دعم Drive API.
نموذج التعليمات البرمجية
تستخدم عيّنات الرموز البرمجية في هذا القسم الإصدار 3 من واجهة برمجة التطبيقات.
تحميل ملفات
يوضّح نموذج الرمز البرمجي التالي كيفية حفظ ملف في
Drive الخاص بالمستخدم.
/** * Uploads a new file to the user's Drive. */functionuploadFile(){try{// Makes a request to fetch a URL.constimage=UrlFetchApp.fetch('http://goo.gl/nd7zjB').getBlob();letfile={name:'google_logo.png',mimeType:'image/png'};// Create a file in the user's Drive.file=Drive.Files.create(file,image,{'fields':'id,size'});console.log('ID: %s, File size (bytes): %s',file.id,file.size);}catch(err){// TODO (developer) - Handle exceptionconsole.log('Failed to upload file with error %s',err.message);}}
سرد المجلدات
يوضّح نموذج الرمز البرمجي التالي كيفية إدراج المجلدات ذات المستوى الأعلى في حساب Drive الخاص بالمستخدم. يُرجى العِلم أنّه يتم استخدام رموز مميزة للصفحات للوصول إلى القائمة الكاملة بالنتائج.
/** * Lists the top-level folders in the user's Drive. */functionlistRootFolders(){constquery='"root" in parents and trashed = false and '+'mimeType = "application/vnd.google-apps.folder"';letfolders;letpageToken=null;do{try{folders=Drive.Files.list({q:query,pageSize:100,pageToken:pageToken});if(!folders.files||folders.files.length===0){console.log('All folders found.');return;}for(leti=0;i < folders.files.length;i++){constfolder=folders.files[i];console.log('%s (ID: %s)',folder.name,folder.id);}pageToken=folders.nextPageToken;}catch(err){// TODO (developer) - Handle exceptionconsole.log('Failed with error %s',err.message);}}while(pageToken);}
مراجعات القائمة
يوضّح نموذج الرمز البرمجي التالي كيفية إدراج المراجعات لملف معيّن. يُرجى العِلم أنّ بعض الملفات يمكن أن تتضمّن عدة مراجعات، وعليك استخدام رموز الصفحات للوصول إلى القائمة الكاملة للنتائج.
/** * Lists the revisions of a given file. * @param {string} fileId The ID of the file to list revisions for. */functionlistRevisions(fileId){letrevisions;constpageToken=null;do{try{revisions=Drive.Revisions.list(fileId,{'fields':'revisions(modifiedTime,size),nextPageToken'});if(!revisions.revisions||revisions.revisions.length===0){console.log('All revisions found.');return;}for(leti=0;i < revisions.revisions.length;i++){constrevision=revisions.revisions[i];constdate=newDate(revision.modifiedTime);console.log('Date: %s, File size (bytes): %s',date.toLocaleString(),revision.size);}pageToken=revisions.nextPageToken;}catch(err){// TODO (developer) - Handle exceptionconsole.log('Failed with error %s',err.message);}}while(pageToken);}
إضافة خصائص الملف
يستخدم نموذج الرمز البرمجي التالي الحقل appProperties لإضافة سمة مخصّصة إلى ملف. لا تظهر السمة المخصّصة إلا للنص البرمجي. لإضافة خاصية مخصّصة إلى الملف يمكن للتطبيقات الأخرى الاطّلاع عليها أيضًا، استخدِم الحقل properties بدلاً من ذلك. لمزيد من المعلومات، يُرجى الاطّلاع على إضافة خصائص ملفات مخصّصة.
/** * Adds a custom app property to a file. Unlike Apps Script's DocumentProperties, * Drive's custom file properties can be accessed outside of Apps Script and * by other applications; however, appProperties are only visible to the script. * @param {string} fileId The ID of the file to add the app property to. */functionaddAppProperty(fileId){try{letfile={'appProperties':{'department':'Sales'}};// Updates a file to add an app property.file=Drive.Files.update(file,fileId,null,{'fields':'id,appProperties'});console.log('ID: %s, appProperties: %s',file.id,JSON.stringify(file.appProperties,null,2));}catch(err){// TODO (developer) - Handle exceptionconsole.log('Failed with error %s',err.message);}}
تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 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,[]]