# Comments Analyzer Agent (`apify/comments-analyzer-agent`) Actor

Prevent PR disasters with AI sentiment analysis. Monitor comments across TikTok, YouTube, and Instagram to detect negative sentiment, toxic content, and potential crises before they escalate. Automate your workflow and send a message when something needs your immediate attention.

- **URL**: https://apify.com/apify/comments-analyzer-agent.md
- **Developed by:** [Apify](https://apify.com/apify) (Apify)
- **Categories:** Agents
- **Stats:** 330 total users, 7 monthly users, 92.1% runs succeeded, 14 bookmarks
- **User rating**: 5.00 out of 5 stars

## Pricing

$1.00 / 1,000 comments

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

### What does Comments Analyzer Agent do?

This Comments Analyzer helps you understand **how audiences react to social media posts** by **analyzing comments for sentiment** (positive, negative, or neutral). It also **flags potentially harmful content.**

🤖 **Tip:** You can easily **set up an automation** to receive information about these comments directly on your preferred communication channel so you can **act before things escalate**. Use Apify internal integrations or one of the automation tools such as Make, Zapier, or n8n.

### How to analyze comments with Comments Analyzer?

1. [Create](https://console.apify.com/sign-up) a free Apify account using your email.
2. **Gather the URLs** of the posts you want to monitor
3. Plug them into the **Comments Analyzer Agent input.**
4. Run the Actor and wait for the analysis to be completed.
5. **Download your data** in JSON, XML, CSV, Excel, or HTML and explore the structured dataset with sentiment results and flagged insights.

### What information can I get with Comments Analyzer Agent?

<table>
<tr>
<td>🗨️ All comments with sentiment analysis (positive, negative, or neutral).</td>
<td>📋 A high-level summary of the sentiment landscape</td>
<td>📈 Absolute and relative counts of positive, negative, and neutral comments</td>
<td>🚩 Red-flagged comments with a highly negative tone or toxic language</td>
</tr>
</table>

### ⬇️ Input

Add the post URLs with comments you want to have analyzed to start the comments analysis.

You can add posts from:

- **TikTok**
- **YouTube**
- **Instagram**

💡**Hint**: Schedule [TikTok](https://apify.com/clockworks/tiktok-scraper), [YouTube](https://apify.com/streamers/youtube-scraper) or [Instagram Scraper](https://apify.com/apify/instagram-scraper) to fill in the input fields automatically based on your criteria.

Here’s an example input:
![Comments Analyzer Input](https://raw.githubusercontent.com/apify-projects/actor-readme-images/refs/heads/master/comments_analyzer_agent_input.png)

And this is the same input, shown in JSON:

```json
{
    "maxComments": 30,
    "postUrl": "https://www.youtube.com/watch?v=shbNYsEnpDs"
}
```

### ⬆️ Output

After the Actor finishes its run, you'll get a dataset with the output.

There, you’ll find the percentage of negative, positive, and neutral comments as well as the sentiment summary:
![Comments Analyzer Output 1](https://raw.githubusercontent.com/apify-projects/actor-readme-images/refs/heads/master/comments_analyzer_agent_output1.png)

Open the key-value store if you want to find out about the sentiment of each comment.
![Comments Analyzer Output 2](https://raw.githubusercontent.com/apify-projects/actor-readme-images/refs/heads/master/comments_analyzer_agent_output2.png)

Here's an example of the output in JSON format:

```json
{
    "commentsDatasetUrl": "https://console.apify.com/storage/datasets/1fUMfuzvXWVRQfmML",
    "sentiment": "The sentiment analysis of the YouTube comments reveals a diverse range of opinions, with each sentiment type offering unique insights into the viewers' perspectives.",
    "positiveSentiment": "The comments expressing positive sentiment were largely supportive and appreciative of the individuals and themes discussed in the video. Many users admired the resilience and humanity of the characters, often highlighting their struggles and achievements. For instance, @Alexis-g7c expressed admiration and respect for the individuals mentioned, while @clara4942 praised William and Kate, referring to Kate as the GOAT (Greatest of All Time). These comments often focused on the positive attributes and contributions of the characters, fostering a sense of admiration and respect among viewers. Common reasons for positive sentiment included empathy for personal sacrifices, appreciation for strong relationships, and admiration for personal qualities such as kindness and resilience.",
    "neutralSentiment": "Neutral comments often reflected a more analytical or observational tone, focusing on factual or historical aspects without strong emotional language. For example, @RadonnaMovies provided a historical reference without expressing a strong opinion, while @aquitaineq questioned a historical fact without a strong emotional tone. These comments typically revolved around seeking clarification or providing context, rather than expressing strong feelings. Common reasons for neutral sentiment included curiosity about historical accuracy, interest in factual details, and a desire for more information without emotional bias.",
    "negativeSentiment": "Negative comments were characterized by critical or derogatory language, often expressing dissatisfaction or disapproval of certain characters or themes. For instance, @mursyidomar6995 used derogatory language to describe a character, while @MoRiley9 expressed a negative opinion about the British royals. These comments often focused on perceived flaws or negative behaviors, leading to a critical perspective. Common reasons for negative sentiment included disagreement with character actions, disapproval of certain behaviors, and negative perceptions of relationships or societal norms. Notably, highly negative comments that were red-flagged, such as those by @mursyidomar6995 and @MoRiley9, contained derogatory language that warranted attention due to their potential impact on the community's tone and inclusivity. \n\nOverall, the comments reflected a mix of positive, neutral, and negative sentiments, with many users expressing admiration for the characters' resilience and humanity, while others critiqued certain behaviors or historical interpretations. The overall sentiment of the comments was largely positive, with many users expressing support and admiration for the individuals and themes discussed. However, there were also critical voices that highlighted perceived flaws or disagreements, contributing to a balanced and diverse discussion. Common themes included appreciation for personal qualities, curiosity about historical accuracy, and critical perspectives on societal norms and behaviors. This diversity of opinions enriched the conversation, offering a comprehensive view of the audience's perspectives.",
    "positivePercentage": "36.67%",
    "neutralPercentage": "33.33%",
    "negativePercentage": "30.00%",
    "totalComments": 30,
    "positiveComments": 11,
    "neutralComments": 10,
    "negativeComments": 9
  }
]
```

And here is the data for each comment in JSON:

```json

    "sentiment": "neutral",
    "sentimentAnalysis": "The comment poses a question about the nature of marriage without expressing a clear positive or negative sentiment.",
    "redFlag": false,
    "commentDetail": {
      "id": "UgyOsza0PxBoE3UagLN4AaABAg",
      "text": "Do you think marriage is a forever contract or has it changed?",
      "likes": 116,
      "date": "8 months ago",
      "author": "@MovingPicsOfficial"
    }
  }
```

### How will Comments Analyzer help me?

📢 **Catch PR disasters before they escalate:** Monitor comment sections and get notified when negativity spikes.

⚠️ **Set up real-time alerts for extreme reactions:** Integrate with Slack, email, or other tools to act on crisis indicators fast.

🕵️ **Run sentiment analysis on competitor content:** Spot weaknesses in competitor messaging and jump into the conversation.

🎯 **Fine-tune your content strategy:** Learn what kind of content resonates or triggers backlash.

📊 **Benchmark sentiment across your videos or competitors:** Track how different posts perform over time or compare sentiment with others in your niche.

### Integrate Comments Analyzer and automate your AI Agents

Comments Analyzer can be connected with almost any cloud service or web app thanks to [integrations](https://apify.com/integrations) on the Apify platform.

These include:

- [Make](https://docs.apify.com/platform/integrations/make)
- [Zapier](https://docs.apify.com/platform/integrations/zapier)
- [Slack](https://docs.apify.com/platform/integrations/slack)
- [Airbyte](https://docs.apify.com/platform/integrations/airbyte)
- [GitHub](https://docs.apify.com/platform/integrations/github)
- [Google Drive](https://docs.apify.com/platform/integrations/drive)
- and [much more](https://docs.apify.com/platform/integrations).

Alternatively, you can use webhooks to carry out an action whenever an event occurs. For example, whenever Comments Analyzer successfully finishes a run, send the summary to a Slack channel or via email.

### FAQ

#### Which platforms are supported?

TikTok, Instagram, and YouTube post URLs are supported.

#### What’s a red-flagged comment?

Red-flagged comments are those with strong negative sentiment, potential for controversy, or emotionally charged content that may escalate.

#### Can I export comments data using API?

Yes, you can access the extracted data through the [**Comments Analyzer Agent** API](https://apify.com/apify/comments-analyzer-agent/api/python). You’ll need an Apify account and your **API token** (available under Integrations settings in the Console). The API is based on RESTful HTTP endpoints that allow you to manage, schedule, and run actors. You can fetch datasets, monitor performance, and integrate with other apps.

For further details, check the [API documentation](https://apify.com/apify/comments-analyzer-agent/api/python).

#### Can I use Comments Analyzer Agent Scraper through an MCP Server?

Yes, you can [integrate](https://apify.com/apify/comments-analyzer-agent/api/mcp) **Comments Analyzer Agent** with AI workflows via the **Model Context Protocol (MCP)**. Follow these steps:

1. Start a Server-Sent Events (SSE) session to receive a `sessionId`.
2. Use the `sessionId` to trigger the scraper.
3. The response should be: `Accepted`.

#### Is it legal to scrape data from social media?

Our [social media scrapers](https://apify.com/store/categories/social-media-scrapers?managedBy=APIFY) operate ethically and extract only publicly available data. For further guidance, you can consult legal advice or check our blog on [ethical web scraping](https://blog.apify.com/what-is-ethical-web-scraping-and-how-do-you-do-it/).

### Not your cup of tea? Build your own Agent

Comments Analyzer doesn’t exactly do what you need?

You can always build your own AI Agent on Apify! Use one of our [templates](https://apify.com/templates) in Python, JavaScript, and TypeScript to get started.

Alternatively, you can write it from scratch using our [open-source library Crawlee](https://crawlee.dev/?__hstc=160404322.99301e3ccb2984c883bfae3081ccc457.1711825637267.1750934794723.1750943322376.898&__hssc=160404322.2.1750943322376&__hsfp=1144682350). You can keep the Actor to yourself or make it public by adding it to Apify Store and [start making money](https://blog.apify.com/how-to-scrape-tiktok-tutorial/) on it.

Or let us know if you need a [custom solution](https://apify.com/custom-solutions).

### Your feedback

We’re always working on improving our Actors' performance. If you have any technical feedback for Comments Analyzer or simply found a bug, please create an issue on the Actor’s Issues tab in Apify Console.

# Actor input Schema

## `postUrl` (type: `string`):

The URL of the post to scrape comments from.

## `maxComments` (type: `integer`):

The maximum number of comments to scrape from each post. If not specified, all comments will be scraped.

## Actor input object example

```json
{
  "postUrl": "https://www.youtube.com/watch?v=52v6gKPA4TM",
  "maxComments": 1
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "postUrl": "https://www.youtube.com/watch?v=52v6gKPA4TM"
};

// Run the Actor and wait for it to finish
const run = await client.actor("apify/comments-analyzer-agent").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "postUrl": "https://www.youtube.com/watch?v=52v6gKPA4TM" }

# Run the Actor and wait for it to finish
run = client.actor("apify/comments-analyzer-agent").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "postUrl": "https://www.youtube.com/watch?v=52v6gKPA4TM"
}' |
apify call apify/comments-analyzer-agent --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,apify/comments-analyzer-agent"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/L8FMdiKphUOJMx9vp/builds/8E1EV9HrjaX5OJh2i/openapi.json
