تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
تتيح لك خدمة "إحصاءات YouTube" استخدام
YouTube Analytics API في Apps Script. تتيح واجهة برمجة التطبيقات هذه للمستخدمين استرداد إحصاءات المشاهدة ومقاييس الرواج والمعلومات الديموغرافية الخاصة بالفيديوهات والقنوات على YouTube.
مراجع
للحصول على معلومات مفصّلة حول هذه الخدمة، يُرجى الاطّلاع على المستندات المرجعية الخاصة بواجهة YouTube Analytics API. مثل جميع الخدمات المتقدّمة في Apps Script، تستخدم خدمة YouTube Analytics الكائنات والطرق والمعلَمات نفسها التي تستخدمها واجهة برمجة التطبيقات العامة. لمزيد من المعلومات، اطّلِع على كيفية تحديد تواقيع الطرق.
نموذج التعليمات البرمجية
يستخدم الرمز البرمجي النموذجي أدناه الإصدار 2 من
YouTube Analytics API، بالإضافة إلى الإصدار 3 من YouTube
Data API، ويمكنك الوصول إليهما من خلال
خدمة YouTube في "برمجة تطبيقات Google".
/** * Creates a spreadsheet containing daily view counts, watch-time metrics, * and new-subscriber counts for a channel's videos. */functioncreateReport(){// Retrieve info about the user's YouTube channel.constchannels=YouTube.Channels.list('id,contentDetails',{mine:true});constchannelId=channels.items[0].id;// Retrieve analytics report for the channel.constoneMonthInMillis=1000*60*60*24*30;consttoday=newDate();constlastMonth=newDate(today.getTime()-oneMonthInMillis);constmetrics=['views','estimatedMinutesWatched','averageViewDuration','subscribersGained'];constresult=YouTubeAnalytics.Reports.query({ids:'channel=='+channelId,startDate:formatDateString(lastMonth),endDate:formatDateString(today),metrics:metrics.join(','),dimensions:'day',sort:'day'});if(!result.rows){console.log('No rows returned.');return;}constspreadsheet=SpreadsheetApp.create('YouTube Analytics Report');constsheet=spreadsheet.getActiveSheet();// Append the headers.constheaders=result.columnHeaders.map((columnHeader)=>{returnformatColumnName(columnHeader.name);});sheet.appendRow(headers);// Append the results.sheet.getRange(2,1,result.rows.length,headers.length).setValues(result.rows);console.log('Report spreadsheet created: %s',spreadsheet.getUrl());}/** * Converts a Date object into a YYYY-MM-DD string. * @param {Date} date The date to convert to a string. * @return {string} The formatted date. */functionformatDateString(date){returnUtilities.formatDate(date,Session.getScriptTimeZone(),'yyyy-MM-dd');}/** * Formats a column name into a more human-friendly name. * @param {string} columnName The unprocessed name of the column. * @return {string} The formatted column name. * @example "averageViewPercentage" becomes "Average View Percentage". */functionformatColumnName(columnName){letname=columnName.replace(/([a-z])([A-Z])/g,'$1 $2');name=name.slice(0,1).toUpperCase()+name.slice(1);returnname;}
تاريخ التعديل الأخير: 2025-07-26 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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-07-26 (حسب التوقيت العالمي المتفَّق عليه)"],[[["The YouTube Analytics API allows you to access viewing statistics, popularity metrics, and demographic data for YouTube videos and channels within Apps Script."],["This is an advanced service that requires enabling before use."],["The provided sample code demonstrates how to create a spreadsheet report containing daily view counts, watch time, and subscriber data for a YouTube channel using the API."],["The API utilizes the same objects, methods, and parameters as the public YouTube Analytics API, ensuring consistency and familiarity for developers."],["For further support and issue reporting, refer to the YouTube API support guide."]]],[]]