//Note:AppsScriptautomaticallyrequestsauthorization//basedontheAPI's used in the code.functionchannelsListByUsername(part,params){varresponse=YouTube.Channels.list(part,params);varchannel=response.items[0];vardataRow=[channel.id,channel.snippet.title,channel.statistics.viewCount];SpreadsheetApp.getActiveSpreadsheet().appendRow(dataRow);}functiongetChannel(){varui=SpreadsheetApp.getUi();varchannelName=ui.prompt("Enter the channel name: ").getResponseText();channelsListByUsername('snippet,contentDetails,statistics',{'forUsername':channelName});}functiongetGoogleDevelopersChannel(){channelsListByUsername('snippet,contentDetails,statistics',{'forUsername':'GoogleDevelopers'});}functiononOpen(){varfirstCell=SpreadsheetApp.getActiveSheet().getRange(1,1).getValue();if(firstCell!='ID'){varheaderRow=["ID","Title","View count"];SpreadsheetApp.getActiveSpreadsheet().appendRow(headerRow);}varui=SpreadsheetApp.getUi();ui.createMenu('YouTube Data').addItem('Add channel data','getCh
[[["易于理解","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"]],["最后更新时间 (UTC):2025-07-09。"],[[["This guide provides a quickstart for creating a Google Apps Script that interacts with the YouTube Data API to add YouTube channel data to a Google Sheet."],["The script retrieves channel ID, title, and view count and populates a spreadsheet with this information, including the ability to add data for a specified channel or the GoogleDevelopers channel."],["Users need a Google account, internet access, a web browser, and access to Google Drive to follow the steps and can turn on the YouTube Data API directly within the Apps Script editor."],["The guide offers a method to run a sample script, which first prompts for authorization, then allows the user to select from a menu to add data either for the GoogleDevelopers channel or for a custom-selected channel."],["A troubleshooting section is available to help resolve common issues, such as the \"\\[API NAME\\]\" is not defined error, and also provides further reading with documentation on the topic."]]],["This guide details how to create a Google Apps Script to fetch and add YouTube channel data to a Google Sheet. The script, once set up, can retrieve channel ID, title, and view count. Key actions include: creating a new Google Sheet, pasting provided code into the Apps Script editor, enabling the YouTube Data API service, and running script options to add either GoogleDevelopers channel data or a user-specified channel's data to the sheet.\n"]]