facebook-business-sdk-unofficial
v0.1.0
Published
Unofficial Facebook Business Suite SDK for posting, uploading photos, and managing pages
Downloads
16
Maintainers
Readme
Facebook Business SDK (Unofficial)
Unofficial SDK for Facebook Business Suite. Post content, upload photos, and manage pages programmatically.
Warning: This is an unofficial SDK that uses Facebook's internal APIs. Use at your own risk. These APIs may change without notice.
Installation
npm install facebook-business-sdk-unofficial
# or
bun add facebook-business-sdk-unofficialSetup
Easy Setup (Recommended)
Just provide your cookies - the SDK will automatically extract the required tokens:
import { FacebookBusiness } from "facebook-business-sdk-unofficial";
// Just need cookies from your browser
const client = await FacebookBusiness.fromCookies("your_cookies_here");To get cookies:
- Login to business.facebook.com
- Open DevTools (F12) → Network tab
- Find any request and copy the
Cookieheader value
Manual Setup
If auto-extraction doesn't work, you can provide tokens manually:
const client = new FacebookBusiness({
cookies: "your_cookies_here",
fbDtsg: "your_fb_dtsg_token",
lsd: "your_lsd_token",
});Usage
Get Pages/Scopes
const { scopes } = await client.getScopes("YOUR_PAGE_ID");
for (const scope of scopes) {
console.log(`${scope.type}: ${scope.name} (${scope.id})`);
}Create a Text Post
const { posts } = await client.createPost({
pageId: "YOUR_PAGE_ID",
message: "Hello from the SDK!",
});
console.log(`Created: ${posts[0].postId}`);Post with Photos
// Upload photo first
const photo = await client.uploadPhoto({
pageId: "YOUR_PAGE_ID",
file: imageFile, // File or Blob
});
// Create post with the photo
await client.createPost({
pageId: "YOUR_PAGE_ID",
message: "Check out this photo!",
photos: [photo],
});Post with Multiple Photos
const photo1 = await client.uploadPhoto({ pageId, file: file1 });
const photo2 = await client.uploadPhoto({ pageId, file: file2 });
await client.createPost({
pageId,
message: "Multiple photos!",
photos: [photo1, photo2],
});Post with Link Preview
await client.createPost({
pageId: "YOUR_PAGE_ID",
message: "Check out this article!",
link: {
url: "https://example.com/article",
title: "Article Title",
summary: "Article description...",
image: "https://example.com/og-image.jpg",
imageWidth: 1200,
imageHeight: 630,
scrapeId: "...", // From Facebook's URL scraper
globalShareId: "...", // From Facebook's URL scraper
hmac: "...", // From Facebook's URL scraper
},
});API Reference
FacebookBusiness
Constructor
new FacebookBusiness(config: ClientConfig)| Property | Type | Description |
|----------|------|-------------|
| cookies | string | Full cookie string from browser |
| fbDtsg | string | CSRF token from request body |
| lsd | string | LSD token from request body |
Methods
getScopes(assetId: string): Promise<ScopesResult>
Get all pages and assets you have access to.
createPost(options: CreatePostOptions): Promise<CreatePostResult>
Create a post on a Facebook page.
| Option | Type | Description |
|--------|------|-------------|
| pageId | string | The page ID to post to |
| message | string | Post text content |
| photos? | UploadedPhoto[] | Photos to attach |
| link? | ScrapedLink | Link preview data |
| channels? | PostChannel[] | Where to post (default: ["FACEBOOK_NEWS_FEED"]) |
uploadPhoto(options: UploadPhotoOptions): Promise<UploadedPhoto>
Upload a photo for use in posts.
| Option | Type | Description |
|--------|------|-------------|
| pageId | string | The page ID |
| file | File \| Blob | The image file |
License
MIT
