YouTube Comment Sentiment Analysis with Google Sheets & OpenAI - n8n Workflow

Automate YouTube comment analysis using a powerful n8n workflow. Integrate OpenAI for sentiment classification (Positive/Negative/Neutral) and store results automatically in Google Sheets. Utilize this specialized n8n template for data logging.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Digital Marketing Agencies: Monitoring public reception and campaign effectiveness across YouTube content.
Content Creators & YouTubers: Automatically tracking audience feedback and sentiment across their video library.
Market Researchers: Collecting structured, classified social data for analysis.
Automation Specialists: Seeking advanced examples of using conditional logic and API pagination within a complex n8n workflow.

Overview

Analyzing hundreds or thousands of YouTube comments manually is tedious and time-consuming. This specialized n8n workflow solves this problem by creating an automated pipeline that connects the YouTube Data API, OpenAI's powerful language models, and Google Sheets for structured storage.

This comprehensive n8n template is designed to be highly efficient, featuring internal rate-limiting logic that checks a nextfetchtime timestamp stored in Google Sheets before executing the resource-intensive YouTube API calls. Once new comments are fetched, the workflow uses the LangChain Sentiment Analysis n8n node, powered by OpenAI, to categorize each comment as Positive, Neutral, or Negative. Finally, the categorized data is persisted in a Google Sheet, ensuring that you always have up-to-date, actionable sentiment data without manual intervention. This entire process demonstrates the power and flexibility of a robust n8n automation solution.

How it Works

The execution of this n8n workflow begins with the Manual Trigger (which should be replaced by a Cron n8n trigger for scheduled operation).


  1. Data Retrieval & Throttling: The workflow first runs the 'Get Video Urls from Google Sheet' n8n node, retrieving a list of video URLs and associated timestamps (nextfetchtime). It uses two 'If' n8n node checks ('check next fetch time is available or not' and 'check next fetch time is before the current time') to implement throttling, ensuring API calls are made only after a waiting period (5 minutes, as defined in the final step).

  2. API Interaction: If the timing check passes, the 'Get Comments for video urls' HTTP Request n8n node queries the YouTube Data API, handling pagination automatically to retrieve all available top-level comments for the specified video.

  3. Error Handling & Splitting: A 'Check Success Response' If n8n node ensures the response status code is 200 before proceeding. The 'Split Out' n8n node then separates the bulk API response into individual data items, one for each comment, enabling granular processing.

  4. AI Analysis: The 'OpenAI Chat Model' and 'Analyze sentiment of every comment' n8n nodes collaborate. The LangChain Sentiment Analysis n8n node uses the input comment text and the configured gpt-4o-mini model to determine and output the sentiment category (Positive, Neutral, or Negative).

  5. Data Structuring: The 'Format fields as required...' Set n8n node standardizes the collected data (comment ID, video URL, author, likes, and the analyzed sentiment) into a unified structure.

  6. Persistence & Logging: The 'Insert and update comment in google sheet' n8n node performs an appendOrUpdate operation on the main result sheet using the comment ID as the unique key, preventing duplicate entries. This step ensures consistent data logging.

  7. Workflow Completion: Finally, the 'Update last fetched time and nextfetchtime' n8n node updates the throttling sheet, setting the new lastfetchedtime and scheduling the next permitted execution time (5 minutes in the future). This sophisticated flow ensures reliable, scheduled operation of the n8n workflow.

Installation Guide

To deploy this expert n8n workflow template, follow these steps:


  1. Import: Copy the provided JSON code and paste it into your n8n canvas using the 'New' -> 'Import from JSON' option.

  2. Credentials Setup: You will need three main credentials:

Google Sheets (Service Account): Set up a service account to allow n8n read and write access to your Google Sheet document.
YouTube Data API v3 (HTTP Query Auth): Configure an HTTP Query Authentication credential containing your YouTube API key.
OpenAI API Key: Configure the API key for the 'OpenAI Chat Model' n8n node. This is essential for the sentiment analysis.

  1. Google Sheet Preparation: Ensure your target Google Sheet document has two sheets configured exactly as described in the sticky note:

Sheet1 (Results): Used for storing analyzed comments (commentId, sentiment, videourl, etc.).
* Sheet2 (Configuration): Used for inputting video URLs and tracking the execution timestamps (last
fetchedtime, nextfetch_time).

  1. Activation: Once credentials are set and the Google Sheet IDs are updated in the respective n8n node parameters, save and activate the n8n workflow. Replace the 'When clicking ‘Test workflow’' n8n node with a production-ready schedule, like a Cron n8n trigger.

Node Details

When clicking ‘Test workflow’ (Manual Trigger): The initiating n8n trigger. Used for testing, but typically replaced by a scheduling n8n node for production.
Get Video Urls from Google Sheet (Google Sheets): Reads the list of YouTube URLs and timing data from the designated configuration sheet (Sheet2) using a service account.
check next fetch time is available or not (If): Core logic n8n node. Determines if the workflow is permitted to proceed based on whether the nextfetchtime has been set previously.
Get Comments for video urls (HTTP Request): Connects to the YouTube Data API. Extracts the video ID from the URL and fetches up to 100 comments per request, utilizing custom pagination logic to retrieve large datasets efficiently.
Check Success Response (If): Ensures the YouTube API request returned a successful status code (200) before processing the returned data.
Split Out (Split Out): Crucial n8n node for iteration. It breaks the array of comments received from the API into separate items so that each comment can be analyzed individually by the AI.
OpenAI Chat Model (LangChain Chat OpenAI): Provides the AI engine (using gpt-4o-mini) required by the subsequent sentiment analysis component.
Analyze sentiment of every comment (LangChain Sentiment Analysis): Executes the core AI task. It takes the raw comment text and classifies its emotional tone into Positive, Neutral, or Negative. This specialized n8n node streamlines interaction with large language models.
Insert and update comment in google sheet (Google Sheets): The destination n8n node. Appends new comments or updates existing ones based on the unique commentId in the primary results sheet (Sheet1).
Update last fetched time and nextfetchtime (Google Sheets): The final step of this n8n workflow. It updates the configuration sheet (Sheet2) with the current timestamp and schedules the next run 5 minutes later, enforcing rate limiting.

Related n8n Workflows

Paid

Nodes: 10 Nodes
Updated: December 26 2025
View all
Created by
Aayushman Sharma
Aayushman Sharma

Featured*