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
Extract post data from Facebook
Learn how to scrape Facebook posts using Node.js. This comprehensive guide will walk you through the entire process, from setup to implementation.
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.
Make sure you have the following installed:
Axios is a promise-based HTTP client for Node.js
npm install axios
Now let's make a request to the Facebook API using Node.js. Replace YOUR_API_KEY
with your actual API key.
import axios from 'axios';
const API_KEY = 'YOUR_API_KEY';
async function scrape() {
try {
const response = await axios.get(`https://api.scrapecreators.com/v1/facebook/post?url=https://www.facebook.com/reel/1535656380759655&get_comments=false&get_transcript=false`, {
headers: {
'x-api-key': API_KEY,
'Content-Type': 'application/json'
}
});
console.log('Response:', response.data);
return response.data;
} catch (error) {
console.error('Error:', error.response?.data || error.message);
}
}
// Usage
scrape();
This endpoint accepts the following parameters:
url
Required(string)The URL of the post to get
Example: https://www.facebook.com/reel/1535656380759655
get_comments
Optional(boolean)Whether you want to get the first several comments of the post
Example: false
get_transcript
Optional(boolean)Whether you want to get the transcript of the post
Example: false
Execute your script to test the API connection. You should see a JSON response with Facebook posts data.
✅ Success: You should receive a structured JSON response containing the requested data.
Here's an example of the JSON response you'll receive:
{
"success": true,
"credits_remaining": 48026,
"post_id": "25118307061088489",
"like_count": 2095,
"comment_count": 48,
"share_count": 133,
"view_count": 133000,
"description": "Air Fryer Chocolate Cake \n\n100% f*cks, super simple and comes out gooey in the middle. 🍆 \n\n👨🍳 Ingredients:\n✅ 1 large banana – 100 g (3.5 oz)\n✅ 80 g vanilla YoPro yogurt (2.8 oz / ⅓ cup)\n✅ 15 g Cadbury Bournville cocoa (0.5 oz / 1 tbsp)\n✅ 80 ml egg whites (2.7 fl oz / ⅓ cup)\n✅ 50 g oat flour (1.75 oz / ½ cup)\n✅ 1 tsp vanilla extract (5 ml)\n✅ ½ tsp baking powder (2.5 g)\n👉 Optional: 1 square dark chocolate (10 g / 0.35 oz, ~55 cals)\n\n🔥 Method:\n 1. Mix banana, egg whites, yogurt, cocoa and vanilla until smooth\n 2. Stir in oat flour and baking powder\n 3. Pour into a ramekin or muffin tin\n 4. Add chocolate square to the centre if using\n 5. Air fry at 160°C / 320°F for 20 minutes\n\n📊 Macros (whole recipe):\nWithout choc: 378 cals | 27 g protein | 61.9 g carbs | 6 g fat\nWith choc: 433 cals | 27 g protein | 61.9 g carbs | 11.5 g fat\n\n📊 Macros (per serve — 2 serves):\nWithout choc: 189 cals | 13.5g protein | 31 g carbs | 3 g fat\nWith choc: 217 cals | 13.5 g protein | 31 g carbs | 5.8 g fat\n\nI also added low-calorie Peters ice cream and a small drizzle of Biscoff, but it honestly doesn’t need it. Tastes great on its own!\n\nIf you would like to make changes to this recipe yourself please do, but I like this EXACTLY the way it is. 🤝🫡",
"feedback_id": "ZmVlZGJhY2s6MjUxMDIxMDY3OTkzNzUxODI=",
"url": "https://www.facebook.com/reel/1535656380759655",
"image_url": null,
"video": {
"id": "1535656380759655",
"sd_url": "https://video-fml1-1.xx.fbcdn.net/o1/v/t2/f2/m69/AQPmP0-_mHv5cFqZShaBXjVeIgFmk-_1-6fll0qvoiw3O_StvDRD1FPZafKE0Mri9p94smEKiXpdPjrMnIk2qesQ.mp4?strext=1&_nc_cat=106&_nc_sid=8bf8fe&_nc_ht=video-fml1-1.xx.fbcdn.net&_nc_ohc=l9xG1fq_DpcQ7kNvwHsNBKh&efg=eyJ2ZW5jb2RlX3RhZyI6Inhwdl9wcm9ncmVzc2l2ZS5GQUNFQk9PSy4uQzMuMzYwLnByb2dyZXNzaXZlX2gyNjQtYmFzaWMtZ2VuMl8zNjBwIiwieHB2X2Fzc2V0X2lkIjo4MTEzOTQ4MTQ3NDY5NjAsInZpX3VzZWNhc2VfaWQiOjEwMDk5LCJkdXJhdGlvbl9zIjoyMywidXJsZ2VuX3NvdXJjZSI6Ind3dyJ9&ccb=17-1&_nc_gid=pXV0rbdIO2qXvelwzem88A&_nc_zt=28&oh=00_AfYY-br7Wa1JiPzs7_0vVr6SEV6zDf7qREmd6IV2xBGYMA&oe=68D239F0&bitrate=313736&tag=progressive_h264-basic-gen2_360p",
"hd_url": "https://video-fml1-1.xx.fbcdn.net/o1/v/t2/f2/m69/AQPvY-B_jtS_HwdB--AaOLTiMpw_euZ4QZoJbbh4iBl-faYyL6mYoumXJPqDF8qAnvZk8_SN5QOUds3tDfP0Bfa0.mp4?strext=1&_nc_cat=109&_nc_sid=8bf8fe&_nc_ht=video-fml1-1.xx.fbcdn.net&_nc_ohc=Z4s5wsMtW5wQ7kNvwFE0mwo&efg=eyJ2ZW5jb2RlX3RhZyI6Inhwdl9wcm9ncmVzc2l2ZS5GQUNFQk9PSy4uQzMuNzIwLnByb2dyZXNzaXZlX2gyNjQtYmFzaWMtZ2VuMl83MjBwIiwieHB2X2Fzc2V0X2lkIjo4MTEzOTQ4MTQ3NDY5NjAsInZpX3VzZWNhc2VfaWQiOjEwMDk5LCJkdXJhdGlvbl9zIjoyMywidXJsZ2VuX3NvdXJjZSI6Ind3dyJ9&ccb=17-1&_nc_gid=pXV0rbdIO2qXvelwzem88A&_nc_zt=28&oh=00_AfZJDoPCKtq3WW2VumFViHPpmIkGGqG34j9MWd9FmGrCVg&oe=68D25899&bitrate=1088662&tag=progressive_h264-basic-gen2_720p",
"height": 1920,
"width": 1080,
"length_in_second": 23.36,
"thumbnail": "https://scontent-fml1-1.xx.fbcdn.net/v/t51.82787-10/549761436_18521992156021539_7633323777597918486_n.jpg?stp=dst-jpg_s960x960_tt6&_nc_cat=103&ccb=1-7&_nc_sid=282d23&_nc_ohc=1LkTvLqxMhAQ7kNvwF2uUb7&_nc_oc=AdlKRAdNOj6ZDiga-3Zfj5bcwvfc68Lc39nsYJQ0hSPWGsRtUZJZ_sPCk25DrZJ2N98&_nc_zt=23&_nc_ht=scontent-fml1-1.xx&_nc_gid=pXV0rbdIO2qXvelwzem88A&oh=00_AfZy5UXtBdlEMJc6E6uLLiTvR15d344Nn4PO-wNA0cldQQ&oe=68D25528",
"captions_url": "https://scontent-fml1-1.xx.fbcdn.net/v/t39.2093-6/548496336_1535656704092956_4849526113470105591_n.srt?_nc_cat=105&ccb=1-7&_nc_sid=c211c2&_nc_ohc=IiEVsW2fSK0Q7kNvwEeCqpW&_nc_oc=AdmC4PNaIEGYuNZo_Qk6Qha6U8-ynQip-CKdvOrtQBRqTCrO8nOb6C5kABxPkLO4Vdc&_nc_zt=14&_nc_ht=scontent-fml1-1.xx&_nc_gid=pXV0rbdIO2qXvelwzem88A&oh=00_AfaJjBR2lJhhXTUO5hl0FWPGIlLxjVfuGMmTKUWSEtf6xA&oe=68D23D9F"
},
"author": {
"id": "100000076236457",
"name": "Matt West",
"is_verified": true,
"url": "https://www.facebook.com/matt.west.184",
"image": "https://scontent-fml1-1.xx.fbcdn.net/v/t39.30808-1/485744182_9938984382780671_4072259528431711152_n.jpg?stp=cp0_dst-jpg_s40x40_tt6&_nc_cat=1&ccb=1-7&_nc_sid=1d2534&_nc_ohc=zu8xeHB9r5gQ7kNvwGWw84m&_nc_oc=AdkZ2Ef1ReB34aXLnnIpd4KHQ95nC0wAYS1GptVwcltvxMBjKXEU_D-mebY8WPwkhGI&_nc_zt=24&_nc_ht=scontent-fml1-1.xx&_nc_gid=pXV0rbdIO2qXvelwzem88A&oh=00_AfbFDYlovggVMiDAQp2_r7Ou-o0RG4T0VPbLMxVTfPlW7g&oe=68D250E6"
},
"music": {
"id": "1506592770696336",
"type": "CUSTOM_AUDIO",
"track_title": "Matt West · Original audio",
"music_album_art": "https://scontent-fml1-1.xx.fbcdn.net/v/t39.30808-1/485744182_9938984382780671_4072259528431711152_n.jpg?stp=cp0_dst-jpg_s64x64_tt6&_nc_cat=1&ccb=1-7&_nc_sid=1d2534&_nc_ohc=zu8xeHB9r5gQ7kNvwGWw84m&_nc_oc=AdkZ2Ef1ReB34aXLnnIpd4KHQ95nC0wAYS1GptVwcltvxMBjKXEU_D-mebY8WPwkhGI&_nc_zt=24&_nc_ht=scontent-fml1-1.xx&_nc_gid=pXV0rbdIO2qXvelwzem88A&oh=00_AfZEGmsJmX51XXJTwXi90sPYazNybtjik0KhIFczr3jqIg&oe=68D250E6"
}
}
Check that your response includes the expected fields:
success
(boolean)credits_remaining
(number)post_id
(string)like_count
(number)comment_count
(number)Implement comprehensive error handling and retry logic for failed requests. Log errors properly for debugging.
Cache responses when possible to reduce API calls and improve performance. Consider data freshness requirements.
Never expose your API key in client-side code. Use environment variables and secure key management practices.
When scraping multiple posts, consider batching requests to maximize throughput while staying within rate limits.
Use asynchronous processing in Node.js to handle multiple requests concurrently and improve overall performance.
Analyze Facebook posts to understand market trends, competitor analysis, and audience insights.
Track performance metrics, engagement rates, and content trends across Facebook posts.
Identify potential customers and business opportunities throughFacebook data analysis.
Check your API key is correct and properly formatted in the x-api-key header.
You ran out of credits and need to buy more.
The resource might not exist or be private.
Temporary server issue. Implement retry logic with exponential backoff.
ScrapeCreators offers 100 free API calls to get started. After that, pricing starts at $10 for 5k requests with volume discounts available.
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.
There is no rate limit! So you can scrape as fast as you want!
All API responses are returned in JSON format, making it easy to integrate with any programming language or application.
Yes! This tutorial focuses on core Node.js HTTP concepts that work with any framework. The API calls remain the same regardless of your specific Node.js setup.
For large datasets, implement pagination, use streaming responses where available, and consider storing data in a database for efficient querying.
Get started with 100 free API calls. No credit card required.