Tutorial Β· Facebook

🎯 C# Step-by-step

How to scrape Facebook comments
with C#.

Extract comments data from Facebook. Real code, real responses, real production patterns β€” paste it into your project and ship.

Overview

Learn how to scrape Facebook comments using C#. This comprehensive guide will walk you through the entire process, from setup to implementation.

What You'll Learn

  • β€’ Setting up your development environment
  • β€’ Installing the required HTTP client
  • β€’ Authenticating with the ScrapeCreators API
  • β€’ Making requests to Facebook
  • β€’ Handling responses and errors
  • β€’ Best practices for production use

What You'll Get

  • β€’ Access to comments data
  • β€’ JSON formatted responses
  • β€’ Real-time data access
  • β€’ Scalable solution
  • β€’ Error handling patterns
  • β€’ Performance optimization tips

Prerequisites

1. API Key

First, you'll need a ScrapeCreators API key to authenticate your requests.

Sign up at app.scrapecreators.com to get your free API key with 100 requests.

2. Development Environment

Make sure you have the following installed:

  • β€’ C# and its dependencies
  • β€’ A code editor (VS Code, Sublime, etc.)
  • β€’ Basic understanding of API requests
  • β€’ Command line interface access

Step 1: Install HTTP Client

RestSharp is a simple REST and HTTP API client for .NET

nuget
dotnet add package RestSharp

Step 2: API Implementation

Now let's make a request to the Facebook API using C#. Replace YOUR_API_KEY with your actual API key.

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net;
using System.Threading.Tasks;

class Program
{
    private static readonly string API_KEY = "YOUR_API_KEY";
    private static readonly string BASE_URL = "https://api.scrapecreators.com";
    private static readonly string ENDPOINT_PATH = "/v1/facebook/post/comments";

    static async Task Main(string[] args)
    {
        try
        {
            var result = await ScrapeAsync();
            Console.WriteLine($"Response: {result}");
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Error: {ex.Message}");
        }
    }

    static async Task<string> ScrapeAsync()
    {
        using (var client = new HttpClient())
        {
            client.DefaultRequestHeaders.Add("x-api-key", API_KEY);
            client.DefaultRequestHeaders.Add("Accept", "application/json");

            var queryParams = new Dictionary<string, string>
            {
                { "url", "https://www.facebook.com/reel/753347914167361" },
                { "feedback_id", "ZmVlZGJhY2s6MTQ0NzY1NjMyMzM4Mzg0OA==" },
                { "cursor", "MToxNzU3MTA2NzYyOgF1P1VkxpkA9Ds4..." }
            };

            var queryString = string.Join("&", 
                queryParams.Select(kvp => $"{kvp.Key}={WebUtility.UrlEncode(kvp.Value)}"));

            var url = $"{BASE_URL}{ENDPOINT_PATH}?{queryString}";
            
            var response = await client.GetAsync(url);
            response.EnsureSuccessStatusCode();
            
            return await response.Content.ReadAsStringAsync();
        }
    }
}

Step 3: Testing Your Code

API Parameters

This endpoint accepts the following parameters:

urlOptional(string)

Facebook post URL (or reel URL)

Example: https://www.facebook.com/reel/753347914167361

feedback_idOptional(string)

Using feedback_id (instead of url) will *really* speed up the request. You can get the feedback_id when you make a request to /v1/facebook/post.

Example: ZmVlZGJhY2s6MTQ0NzY1NjMyMzM4Mzg0OA==

cursorOptional(string)

Cursor to get more comments. Get 'cursor' from previous response.

Example: MToxNzU3MTA2NzYyOgF1P1VkxpkA9Ds4...

Run Your Code

Execute your script to test the API connection. You should see a JSON response with Facebook comments data.

βœ… Success: You should receive a structured JSON response containing the requested data.

Expected Response

Here's an example of the JSON response you'll receive:

Sample Response
{
  "success": true,
  "credits_remaining": 49999299370,
  "comments": [
    {
      "id": "Y29tbWVudDoxMjA2OTAzNjAxNDgzOTYwXzc3OTIzNDI4MTE0NjkzNQ==",
      "text": "Do 1/2 mini Oreos and 1/2 peanut butter ritz Bitz, otherwise the same recipe. It’s the BEST",
      "created_at": "2025-09-01T01:10:40.000Z",
      "reply_count": 1,
      "reaction_count": 95,
      "reactions": {
        "thankful": 0,
        "like": 79,
        "love": 4,
        "care": 0,
        "haha": 1,
        "wow": 11,
        "sad": 0,
        "anger": 0,
        "pride": 0,
        "confused": 0
      },
      "author": {
        "id": "pfbid02SdzVLPYTHY2eGMdrwFrLw54sVZdguAGnLUj4RPL3HxFtG2D4PBBjptiMEwpB21Ehl",
        "name": "Robin Bergsagel",
        "gender": "FEMALE",
        "short_name": "Robin"
      }
    },
    {
      "id": "Y29tbWVudDoxMjA2OTAzNjAxNDgzOTYwXzEyODEyNTE3NjM3NTEwODM=",
      "text": "Sabrina Cox Jasmin Cox okay but hear me out, dark chocolate chips πŸ‘€",
      "created_at": "2025-09-01T01:31:04.000Z",
      "reply_count": 3,
      "reaction_count": 45,
      "reactions": {
        "thankful": 0,
        "like": 37,
        "love": 6,
        "care": 0,
        "haha": 0,
        "wow": 1,
        "sad": 0,
        "anger": 1,
        "pride": 0,
        "confused": 0
      },
      "author": {
        "id": "pfbid02616R2TFi1idG4Ek5teDkCRbr2ikn3gyXnyAZreGVsyiNPPCeWuk12xmQuaczZoRl",
        "name": "Brittani Crosby",
        "gender": "FEMALE",
        "short_name": "Brittani"
      }
    },
    {
      "id": "Y29tbWVudDoxMjA2OTAzNjAxNDgzOTYwXzEzMjc3MzczMjIyMDEyOTg=",
      "text": "Do these bits have cheese in the middle?",
      "created_at": "2025-09-01T00:52:22.000Z",
      "reply_count": 30,
      "reaction_count": 51,
      "reactions": {
        "thankful": 0,
        "like": 34,
        "love": 2,
        "care": 0,
        "haha": 12,
        "wow": 2,
        "sad": 0,
        "anger": 1,
        "pride": 0,
        "confused": 0
      },
      "author": {
        "id": "1527964450",
        "name": "Jill Carney Strother",
        "gender": "FEMALE",
        "short_name": "Jill"
      }
    },
    {
      "id": "Y29tbWVudDoxMjA2OTAzNjAxNDgzOTYwXzI1MDM5OTI2NjMzMTMxNzU=",
      "text": "Don’t call it puppy chow!",
      "created_at": "2025-09-01T17:23:19.000Z",
      "reply_count": 2,
      "reaction_count": 7,
      "reactions": {
        "thankful": 0,
        "like": 3,
        "love": 0,
        "care": 0,
        "haha": 4,
        "wow": 0,
        "sad": 0,
        "anger": 0,
        "pride": 0,
        "confused": 0
      },
      "author": {
        "id": "pfbid036F2VtdiRuxfxyVQ975mETPVPMpCQXjgmCmxqy9ERMjU3mxqEL4BZLrd2PweDe2YZl",
        "name": "Susan Chapluk",
        "gender": "FEMALE",
        "short_name": "Susan"
      }
    },
    {
      "id": "Y29tbWVudDoxMjA2OTAzNjAxNDgzOTYwXzEzNTU1Mjc1NjI2MDYwNzk=",
      "text": "Peanut butter Ritz bitz?",
      "created_at": "2025-09-01T00:27:01.000Z",
      "reply_count": 11,
      "reaction_count": 44,
      "reactions": {
        "thankful": 0,
        "like": 41,
        "love": 3,
        "care": 0,
        "haha": 0,
        "wow": 0,
        "sad": 0,
        "anger": 0,
        "pride": 0,
        "confused": 0
      },
      "author": {
        "id": "pfbid0yWpY2xax8651xUYKXPH8K9EubVfohvyoiUYEf9bRWquFaWipGbnUcqjiheVx3BpCl",
        "name": "Julie Henry",
        "gender": "FEMALE",
        "short_name": "Julie"
      }
    },
    {
      "id": "Y29tbWVudDoxMjA2OTAzNjAxNDgzOTYwXzc4NzQ2NjY0NzI2NTk4Mw==",
      "text": "How are you not 300lbs?",
      "created_at": "2025-09-01T00:38:58.000Z",
      "reply_count": 20,
      "reaction_count": 97,
      "reactions": {
        "thankful": 0,
        "like": 59,
        "love": 6,
        "care": 0,
        "haha": 30,
        "wow": 1,
        "sad": 0,
        "anger": 1,
        "pride": 0,
        "confused": 0
      },
      "author": {
        "id": "pfbid0B7mpunXGKrQ7FmnoPLK2hBP2uTziU6ZuH7CfobQjToANo2Wcp3hVPoZXmqcpTPr2l",
        "name": "George Bergerac",
        "gender": "MALE",
        "short_name": "George"
      }
    },
    {
      "id": "Y29tbWVudDoxMjA2OTAzNjAxNDgzOTYwXzc3MjEyOTE4NTQ0OTQ4Mw==",
      "text": "OMG can you say diabetes? πŸ˜‚ οΏΌ",
      "created_at": "2025-09-01T04:36:19.000Z",
      "reply_count": 16,
      "reaction_count": 9,
      "reactions": {
        "thankful": 0,
        "like": 5,
        "love": 0,
        "care": 0,
        "haha": 1,
        "wow": 2,
        "sad": 0,
        "anger": 1,
        "pride": 0,
        "confused": 0
      },
      "author": {
        "id": "100010033157652",
        "name": "Gwen Davis Styers",
        "gender": "FEMALE",
        "short_name": "Gwen"
      }
    },
    {
      "id": "Y29tbWVudDoxMjA2OTAzNjAxNDgzOTYwXzE4NTYxMDU2MDg2NjcxNDI=",
      "text": "Better chilled after made!",
      "created_at": "2025-09-01T00:04:49.000Z",
      "reply_count": 0,
      "reaction_count": 3,
      "reactions": {
        "thankful": 0,
        "like": 3,
        "love": 0,
        "care": 0,
        "haha": 0,
        "wow": 0,
        "sad": 0,
        "anger": 0,
        "pride": 0,
        "confused": 0
      },
      "author": {
        "id": "100003087576087",
        "name": "Diane Critcheloe",
        "gender": "FEMALE",
        "short_name": "Diane"
      }
    },
    {
      "id": "Y29tbWVudDoxMjA2OTAzNjAxNDgzOTYwXzE1Mjg1MjE1NTE2NTU1OTg=",
      "text": "This looks like an interesting variant, but I’d be concerned that the Ritz crackers would quickly become slightly soggy-ish, more so than the Crispix cereal does.",
      "created_at": "2025-09-01T14:43:22.000Z",
      "reply_count": 0,
      "reaction_count": 4,
      "reactions": {
        "thankful": 0,
        "like": 4,
        "love": 0,
        "care": 0,
        "haha": 0,
        "wow": 0,
        "sad": 0,
        "anger": 0,
        "pride": 0,
        "confused": 0
      },
      "author": {
        "id": "pfbid0SqgHL4ZQDP1xSFv4ATenAL4Qh1hSidWTC4C97dkAwYWv6pLZ7srfv4Gt8vHPNXTTl",
        "name": "Laurie J Strobel",
        "gender": "FEMALE",
        "short_name": "Laurie"
      }
    },
    {
      "id": "Y29tbWVudDoxMjA2OTAzNjAxNDgzOTYwXzE1Mzc4NDQwOTA1MjAzODg=",
      "text": "Girl I wonder how many got the cheese ritz..",
      "created_at": "2025-09-01T23:54:48.000Z",
      "reply_count": 2,
      "reaction_count": 5,
      "reactions": {
        "thankful": 0,
        "like": 1,
        "love": 0,
        "care": 0,
        "haha": 4,
        "wow": 0,
        "sad": 0,
        "anger": 0,
        "pride": 0,
        "confused": 0
      },
      "author": {
        "id": "pfbid0vn8xpUxRCfS3ZRZSsu9iAVtkHQveKuTFQWbj7h3QVmc7EDQAoPSz32WvX3LUqgP4l",
        "name": "Maegan Nicole Bogue",
        "gender": "FEMALE",
        "short_name": "Maegan"
      }
    }
  ],
  "cursor": "MToxNzc2NDYxMjMwOgF......",
  "has_next_page": true
}

Verify Response Structure

Check that your response includes the expected fields:

  • βœ“success(boolean)
  • βœ“credits_remaining(number)
  • βœ“comments(object)
  • βœ“cursor(string)
  • βœ“has_next_page(boolean)

Best Practices

1

Error Handling

Implement comprehensive error handling and retry logic for failed requests. Log errors properly for debugging.

2

Caching

Cache responses when possible to reduce API calls and improve performance. Consider data freshness requirements.

3

Security

Never expose your API key in client-side code. Use environment variables and secure key management practices.

Performance Tips

Batch Requests

When scraping multiple comments, consider batching requests to maximize throughput while staying within rate limits.

Async Processing

Use asynchronous processing in C# to handle multiple requests concurrently and improve overall performance.

Common Use Cases

Market Research

Analyze Facebook comments to understand market trends, competitor analysis, and audience insights.

Content Analytics

Track performance metrics, engagement rates, and content trends across Facebook comments.

Lead Generation

Identify potential customers and business opportunities throughFacebook data analysis.

Troubleshooting

Common Errors

401 Unauthorized

Check your API key is correct and properly formatted in the x-api-key header.

402 Payment Required

You ran out of credits and need to buy more.

404 Not Found

The resource might not exist or be private.

500 Server Error

Temporary server issue. Implement retry logic with exponential backoff.

Frequently Asked Questions

How much does it cost to scrape Facebook comments?

ScrapeCreators offers 100 free API calls to get started. After that, pricing starts at $10 for 5k requests with volume discounts available.

Is it legal to scrape Facebook data?

Scraping publicly available data is fair game, and we only collect public data. So anything that you can see in an incognito browser is what we collect.

How fast can I scrape Facebook comments?

There is no rate limit! So you can scrape as fast as you want!

What data format does the API return?

All API responses are returned in JSON format, making it easy to integrate with any programming language or application.

Can I use this with other C# frameworks?

Yes! This tutorial focuses on core C# HTTP concepts that work with any framework. The API calls remain the same regardless of your specific C# setup.

How do I handle large datasets?

For large datasets, implement pagination, use streaming responses where available, and consider storing data in a database for efficient querying.

Related Tutorials

Ready to ship?

Get the API key. Run the code.

100 free API calls. No credit card. Same endpoint, same response shape.

Same endpoint, different language

Pick another stack.