This project is a Google Apps Script designed to extract and record information about your YouTube subscribers from Gmail to a Google Sheet. It leverages the Clasp CLI for seamless development and deployment.
- Automated Subscriber Tracking: Automatically pulls subscriber information from YouTube notification emails in Gmail.
- Google Sheet Integration: Records subscriber details (name, channel URL, subscription date) into a Google Sheet.
- Subscriber Link Fixing: Automatically identifies and corrects malformed or encoded YouTube subscriber links and cleans display text in Google Sheets.
- Multi-language Support: Configurable to support different languages for email parsing.
- Easy Deployment: Uses Clasp for easy push and pull of code to Google Apps Script.
These instructions will get you a copy of the project up and running on your local machine for development and deployment.
Before you begin, ensure you have the following installed:
-
Node.js (LTS version recommended)
-
npm (comes with Node.js)
-
Clasp (Google Apps Script CLI)
npm install -g @google/clasp
-
Clone the repository:
git clone https://github.com/chriskyfung/youtube-subscriber-spreadsheet-apps-script.git cd youtube-subscriber-spreadsheet-apps-script -
Install dependencies:
npm install
-
Log in to Clasp:
npm run clasp:login
This will open a browser window and ask you to log in to your Google account. Ensure you log in with the account you want to use for Google Apps Script.
-
Create a new Google Apps Script project:
npm run clasp:create
Clasp CLI will prompt you to select a project type. Choose
"sheets"to create a new Google Spreadsheet-bound script.Self-Correction Note: After creating the project, it is highly recommended to change the
rootDirattribute in the generated.clasp.jsonfile to.. This ensures better project portability and avoids potential issues with Clasp's directory handling.{ "scriptId": "YOUR_SCRIPT_ID", "rootDir": "." } -
Push the project to Google Apps Script:
npm run push
The first time you execute this command, Clasp CLI will ask you to overwrite the manifest file (
appsscript.json) of the project. Typeyand pressEnter. This file contains the necessary configuration for Google to manage permissions and access to your script.
The script can be customized via the src/config.js and src/constants.js files.
This file holds configuration for Gmail search queries and Spreadsheet settings.
This file defines the supported languages and the regular expressions used for parsing subscriber names.
The script currently supports the following languages for parsing subscriber notification emails:
| Language | Search Query Placeholder |
|---|---|
| English | Email subject: {_subscriber Name_} has subscribed to you on YouTube |
| δΈζ(ι¦ζΈ―) | ι»ι΅δΈ»ι‘: {_θ¨ι±θ
ε稱_} θ¨ι±δΊδ½ η YouTube ι »ι |
| δΈζ(ε°η£) | ι»ι΅δΈ»ι‘: {_θ¨ι±θ
ε稱_} θ¨ι±δΊζ¨η YouTube ι »ι |
To add support for a new language, you would need to:
- Add the language code to the
LOCATESarray insrc/constants.js. - Add the corresponding localized phrase to the
LANGobject insrc/constants.js. - Potentially adjust the
regexfunction if the email body structure for the new language significantly differs.
Here are some common issues and their solutions:
- Issue: You're having trouble logging in with
npm run clasp:loginor encountering authentication errors. - Solution:
- Ensure you have a stable internet connection.
- Try clearing your browser's cookies and cache before attempting to log in again.
- Verify that you are logging in with the correct Google account that has access to Google Apps Script.
- If the browser window doesn't open, try running
clasp logindirectly in your terminal to see if there are any specific error messages.
- Issue: The
npm run pushcommand gives errors related to insufficient permissions or API access. - Solution:
- Enable Google Apps Script API: Go to the Google Cloud Console -> APIs & Services -> Dashboard. Search for and ensure the "Google Apps Script API" is enabled for your project.
- Authorize Scopes: When you first push the project, Google may ask for authorization for certain scopes (e.g., Gmail, Spreadsheets). Ensure you grant these permissions. If you previously denied them, you might need to revoke access for Clasp in your Google account settings and re-authenticate.
- Check
appsscript.json: Ensure yourappsscript.jsonfile (the manifest file) correctly defines the required OAuth scopes. For example, to interact with Gmail and Spreadsheets, you'll need scopes likehttps://www.googleapis.com/auth/gmail.readonlyandhttps://www.googleapis.com/auth/spreadsheets.
- Issue: Your script works when tested locally (if applicable), but fails or doesn't behave as expected after
npm run pushand running it in Google Apps Script environment. - Solution:
- Check Logs: Access the Google Apps Script project online (script.google.com), go to "Executions" or "Logs" to see detailed error messages.
- Manifest File (
appsscript.json): Ensure yourappsscript.jsoncorrectly defines all necessary services, triggers, and OAuth scopes. - Environment Differences: Google Apps Script environment is server-side JavaScript. Some Node.js specific features or global objects might not be available. Ensure your code is compatible with the Apps Script runtime.
- Time-driven Triggers: If your script is meant to run automatically, verify that you have set up a time-driven trigger in the Google Apps Script editor (via the clock icon on the left sidebar).
-
Issue: After
npm run clasp:create, therootDirin.clasp.jsonis not set to., leading to deployment issues. -
Solution: Manually edit the
.clasp.jsonfile in your project's root directory and change therootDirvalue to.(a single dot). This tells Clasp to consider your entire project directory as the root for deployment.{ "scriptId": "YOUR_SCRIPT_ID", "rootDir": "." }
This project is licensed under the GNU Affero General Public License Version 3 (AGPL-3.0).
The AGPL-3.0 is a strong copyleft license that ensures software freedom for all users. Key aspects include:
- Source Code Availability: Anyone who uses the software over a network must be provided with the full source code.
- Freedom to Share and Change: Users are free to run, study, share, and modify the software.
- Derivative Works: Any derivative works must also be licensed under AGPL-3.0.
- Network Use: If you modify the software and run it as a service over a network, you must offer the modified source code to the users of that service. This is the main distinction from the GNU General Public License (GPL).
For more details, please refer to the full license text.
Contributions are welcome! Please read our contributing guidelines to get started.
