Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 24, 2025

This PR implements a comprehensive Facebook strategy for the crosspost project, enabling users to post messages and images to Facebook alongside other supported social media platforms.

Features Implemented

Text Posting: Posts messages to Facebook feed via Graph API v18.0
Image Support: Uploads and posts images with captions using the photos endpoint
Error Handling: Comprehensive error handling for API failures, rate limits, and authentication issues
Abort Support: Cancellation support via AbortSignal for long-running operations
URL Generation: Extracts post URLs from API responses for linking back to posts
Input Validation: Follows existing patterns for validating images and options
TypeScript Support: Full type definitions and seamless compilation

Usage Example

import { FacebookStrategy, Client } from '@humanwhocodes/crosspost';

// Initialize the Facebook strategy
const facebook = new FacebookStrategy({
  accessToken: 'your-facebook-access-token'
});

// Use with crosspost client
const client = new Client([facebook]);
await client.post('Hello Facebook! 🌍');

// Post with image
await client.post('Check out this image!', {
  images: [{ data: imageBuffer, alt: 'Description' }]
});

Authentication Requirements

To use this strategy, you need:

  1. A Facebook App registered at https://developers.facebook.com/apps/
  2. An access token with appropriate permissions:
    • pages_manage_posts - For posting to Facebook Pages
    • publish_to_groups - For posting to Facebook Groups
    • User access token with appropriate scope for personal posts

API Integration Details

  • Endpoint: https://graph.facebook.com/v18.0/me/feed for text posts
  • Image Upload: https://graph.facebook.com/v18.0/me/photos for posts with images
  • Character Limit: 63,206 characters (very generous compared to other platforms)
  • Rate Limits: 200 calls per hour per user (standard tier)

Testing

Added comprehensive test suite with 21 test cases covering:

  • Constructor validation
  • Text posting success and failure scenarios
  • Image upload functionality and error handling
  • Input validation for images and options
  • Abort signal support
  • URL extraction from various response formats
  • Message length calculation

All existing tests continue to pass, ensuring no regressions.

Documentation

The strategy includes detailed JSDoc comments explaining:

  • Authentication setup and requirements
  • Required permissions for different use cases
  • Rate limiting considerations
  • Best practices for automated posting
  • Links to Facebook Developer documentation

Fixes #115.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Strategy for Posting to Facebook Add Facebook strategy for posting to Facebook via Graph API Jul 24, 2025
Copilot AI requested a review from nzakas July 24, 2025 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Strategy for Posting to Facebook

2 participants