با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
سرویس YouTube به شما امکان می دهد از YouTube Data API و YouTube Live Streaming API در Apps Script استفاده کنید. این API به کاربران این امکان را می دهد که ویدیوها، لیست های پخش، کانال ها و رویدادهای زنده خود را مدیریت کنند.
مرجع
برای اطلاعات دقیق در مورد این سرویس، به مستندات مرجع زیر مراجعه کنید:
مانند همه سرویسهای پیشرفته در Apps Script، سرویس YouTube از همان اشیا، روشها و پارامترهای API عمومی استفاده میکند. برای اطلاعات بیشتر، نحوه تعیین امضای روش را ببینید.
برای گزارش مشکلات و یافتن پشتیبانی دیگر، به صفحات پشتیبانی مربوطه مراجعه کنید:
کد نمونه زیر از نسخه 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('Unabletosearchvideos');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('Failedwithanerror%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('NoChannelsfound.');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('NoPlaylistfound.');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('Failedwitherr%s',err.message);}}
عضو کانال شوید
این نمونه کاربر را در کانال Google Developers در 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('Addedsubscriptionforchanneltitle:%s',response.snippet.title);}catch(e){if(e.message.match('subscriptionDuplicate')){console.log('Cannotsubscribe;alreadysubscribedtochannel: ' +channelId);}else{// TODO (developer) - Handle exceptionconsole.log('Erroraddingsubscription: ' +e.message);}}}
تاریخ آخرین بهروزرسانی 2025-01-07 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-01-07 بهوقت ساعت هماهنگ جهانی."],[[["The 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."],["This is an advanced service that needs to be enabled before use within your Apps Script project."],["Sample code is provided to demonstrate searching for videos, retrieving user uploads, and subscribing to channels using the API."],["Refer to the YouTube Data API and YouTube Live Streaming API reference documentation for detailed information and further functionalities."]]],[]]