تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
تتيح لك خدمة YouTube استخدام YouTube Data API
وYouTube Live Streaming API في "برمجة التطبيقات". تتيح واجهة برمجة التطبيقات هذه للمستخدمين إدارة فيديوهاتهم وقوائم التشغيل والقنوات والأحداث المباشرة.
مراجع
للحصول على معلومات مفصّلة حول هذه الخدمة، يُرجى الاطّلاع على مستندات المرجع التالية:
مثل جميع الخدمات المتقدّمة في "برمجة التطبيقات"، تستخدم خدمة YouTube الكائنات والطرق والمعلَمات نفسها المستخدَمة في واجهة برمجة التطبيقات العامة. لمزيد من المعلومات، اطّلِع على كيفية تحديد تواقيع الطرق.
للإبلاغ عن مشاكل والعثور على خيارات دعم أخرى، يُرجى الاطّلاع على صفحات الدعم التالية:
يستخدم نموذج الرمز البرمجي أدناه الإصدار 3 من YouTube Data API.
البحث باستخدام كلمة رئيسية
تبحث هذه الدالة عن فيديوهات حول الكلاب، ثم تسجّل معرّفات الفيديوهات وعناوينها.
يُرجى العِلم أنّ هذه العيّنة تحدّ النتائج بـ 25 نتيجة. لعرض المزيد من النتائج، مرِّر مَعلمات إضافية كما هو موضّح في مستندات مرجع YouTube Data API.
/** * Searches for videos about dogs, then logs the video IDs and title. * Note that this sample limits the results to 25. To return more * results, pass additional parameters as shown in the YouTube Data API docs. * @see https://developers.google.com/youtube/v3/docs/search/list */functionsearchByKeyword(){try{constresults=YouTube.Search.list('id,snippet',{q:'dogs',maxResults:25});if(results===null){console.log('Unable to search videos');return;}results.items.forEach((item)=>{console.log('[%s] Title: %s',item.id.videoId,item.snippet.title);});}catch(err){// TODO (developer) - Handle exceptions from Youtube APIconsole.log('Failed with an error %s',err.message);}}
استرداد الفيديوهات المحمَّلة
تستردّ هذه الدالة الفيديوهات التي حمّلها المستخدم. ويتم ذلك باتّباع الخطوات التالية:
يجلب قناة المستخدم
يجلب قائمة التشغيل uploads الخاصة بالمستخدم
تكرّر هذه الدالة قائمة التشغيل وتسجّل معرّفات الفيديوهات وعناوينها
إذا كانت هناك صفحة نتائج تالية، يتم جلبها، ثم يتم الرجوع إلى الخطوة 3
/** * This function retrieves the user's uploaded videos by: * 1. Fetching the user's channel's. * 2. Fetching the user's "uploads" playlist. * 3. Iterating through this playlist and logs the video IDs and titles. * 4. If there is a next page of resuts, fetching it and returns to step 3. */functionretrieveMyUploads(){try{// @see https://developers.google.com/youtube/v3/docs/channels/listconstresults=YouTube.Channels.list('contentDetails',{mine:true});if(!results||results.items.length===0){console.log('No Channels found.');return;}for(leti=0;i < results.items.length;i++){constitem=results.items[i];/** Get the channel ID - it's nested in contentDetails, as described in the * Channel resource: https://developers.google.com/youtube/v3/docs/channels. */constplaylistId=item.contentDetails.relatedPlaylists.uploads;letnextPageToken=null;do{// @see: https://developers.google.com/youtube/v3/docs/playlistItems/listconstplaylistResponse=YouTube.PlaylistItems.list('snippet',{playlistId:playlistId,maxResults:25,pageToken:nextPageToken});if(!playlistResponse||playlistResponse.items.length===0){console.log('No Playlist found.');break;}for(letj=0;j < playlistResponse.items.length;j++){constplaylistItem=playlistResponse.items[j];console.log('[%s] Title: %s',playlistItem.snippet.resourceId.videoId,playlistItem.snippet.title);}nextPageToken=playlistResponse.nextPageToken;}while(nextPageToken);}}catch(err){// TODO (developer) - Handle exceptionconsole.log('Failed with err %s',err.message);}}
الاشتراك في القناة
يشترك هذا النموذج في قناة "مطوّرو Google" على YouTube.
/** * This sample subscribes the user to the Google Developers channel on YouTube. * @see https://developers.google.com/youtube/v3/docs/subscriptions/insert */functionaddSubscription(){// Replace this channel ID with the channel ID you want to subscribe toconstchannelId='UC_x5XG1OV2P6uZZ5FSM9Ttw';constresource={snippet:{resourceId:{kind:'youtube#channel',channelId:channelId}}};try{constresponse=YouTube.Subscriptions.insert(resource,'snippet');console.log('Added subscription for channel title : %s',response.snippet.title);}catch(e){if(e.message.match('subscriptionDuplicate')){console.log('Cannot subscribe; already subscribed to channel: '+channelId);}else{// TODO (developer) - Handle exceptionconsole.log('Error adding subscription: '+e.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 YouTube service in Apps Script allows you to manage videos, playlists, channels, and live events using the YouTube Data API and YouTube Live Streaming API.\u003c/p\u003e\n"],["\u003cp\u003eThis is an advanced service that needs to be enabled before use within your Apps Script project.\u003c/p\u003e\n"],["\u003cp\u003eSample code is provided to demonstrate searching for videos, retrieving user uploads, and subscribing to channels using the API.\u003c/p\u003e\n"],["\u003cp\u003eRefer to the YouTube Data API and YouTube Live Streaming API reference documentation for detailed information and further functionalities.\u003c/p\u003e\n"]]],[],null,[]]