YouTube Analytics
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
สร้างรายงานสำหรับช่อง
function runYoutubeAnalyticsReport() {
// Get the list of all channels.
var myChannels = YouTube.Channels.list('id', {mine: true});
// Pick the first available channel.
var channel = myChannels.items[0];
var channelId = channel.id;
// Set the dates for report.
var today = new Date();
var oneMonthAgo = new Date();
oneMonthAgo.setMonth(today.getMonth() - 1);
var todayFormatted = Utilities.formatDate(today, 'UTC', 'yyyy-MM-dd');
var oneMonthAgoFormatted = Utilities.formatDate(oneMonthAgo, 'UTC',
'yyyy-MM-dd');
// See https://developers.google.com/youtube/analytics/v1/reports for
// supported dimensions and metrics.
var analyticsResponse = YouTubeAnalytics.Reports.query(
'channel==' + channelId,
oneMonthAgoFormatted,
todayFormatted,
'views,likes,dislikes,shares',
{
dimensions: 'day',
sort: '-day'
});
console.log(analyticsResponse);
}
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-21 UTC
[null,null,["อัปเดตล่าสุด 2025-08-21 UTC"],[[["\u003cp\u003eThis script utilizes the YouTube Data API to generate a report for your YouTube channel.\u003c/p\u003e\n"],["\u003cp\u003eIt retrieves data from the past month, including daily views, likes, dislikes, and shares.\u003c/p\u003e\n"],["\u003cp\u003eThe report focuses on the performance of a single channel, prioritizing the first one found in your account if you have multiple.\u003c/p\u003e\n"],["\u003cp\u003eData is formatted for logging to the console, providing a raw overview of your channel's recent activity.\u003c/p\u003e\n"]]],[],null,["# YouTube Analytics\n\nCreate report for a channel\n---------------------------\n\n```gdscript\nfunction runYoutubeAnalyticsReport() {\n // Get the list of all channels.\n var myChannels = YouTube.Channels.list('id', {mine: true});\n\n // Pick the first available channel.\n var channel = myChannels.items[0];\n var channelId = channel.id;\n\n // Set the dates for report.\n var today = new Date();\n var oneMonthAgo = new Date();\n oneMonthAgo.setMonth(today.getMonth() - 1);\n\n var todayFormatted = Utilities.formatDate(today, 'UTC', 'yyyy-MM-dd');\n var oneMonthAgoFormatted = Utilities.formatDate(oneMonthAgo, 'UTC',\n 'yyyy-MM-dd');\n\n // See https://developers.google.com/youtube/analytics/v1/reports for\n // supported dimensions and metrics.\n var analyticsResponse = YouTubeAnalytics.Reports.query(\n 'channel==' + channelId,\n oneMonthAgoFormatted,\n todayFormatted,\n 'views,likes,dislikes,shares',\n {\n dimensions: 'day',\n sort: '-day'\n });\n console.log(analyticsResponse);\n}\n```"]]