facebook-api-rs
A Rust client library for the Facebook Graph API v23.0, with full support for both native and WebAssembly (WASM) environments.
Features
- ✅ Facebook Graph API v23.0 - Latest version with 2-year support guarantee
- 🦀 Rust & WASM - Works in both backend servers and frontend browsers
- 🔐 OAuth Flow - Complete manual login flow implementation
- 📄 Pages API - Manage Facebook pages, posts, photos, and videos
- 📸 Instagram Business API - Access Instagram business accounts, media, and hashtags
- 🔄 Batch Requests - Optimize API calls with batch operations
- ⚡ Async/Await - Modern asynchronous Rust patterns
- 🎯 Type-Safe - Strongly-typed API responses with serde
- 🔧 Flexible HTTP - Choose between
reqwest
(default) orweb-sys
for HTTP
Requirements
- Rust 1.81.0 or later
- A Facebook App with App ID and App Secret (Create one here)
- Valid Facebook access tokens for API calls
Documentation
Installation
Add this to your Cargo.toml
:
[]
= "0.1.2"
Or install via cargo:
Alternative: Install from Git
You can also install directly from GitHub:
[]
= { = "https://github.com/osain-az/facebook-api-rs" }
Or specify a particular branch, tag, or commit:
[]
# Use main branch
= { = "https://github.com/osain-az/facebook-api-rs", = "main" }
# Use specific tag
= { = "https://github.com/osain-az/facebook-api-rs", = "v0.1.0" }
# Use specific commit
= { = "https://github.com/osain-az/facebook-api-rs", = "abc123" }
Feature Flags
The crate provides two HTTP client implementations:
reqwest
(default) - Uses reqwest for native and WASM targetsweb-sys
- Uses web-sys for browser-based WASM applications
Using the Default Feature (reqwest)
[]
= { = "https://github.com/osain-az/facebook-api-rs" }
Using web-sys for WASM
[]
= { = "https://github.com/osain-az/facebook-api-rs", = false, = ["web-sys"] }
Quick Start
1. Build a Login URL
Generate a Facebook OAuth login URL to authenticate users:
use ;
2. Handle OAuth Callback
After users authenticate, extract tokens from the redirect URL:
use UserToken;
async
3. Make API Calls
Use the client to interact with Facebook Graph API:
use ;
async
API Version Configuration
By default, this crate uses Facebook Graph API v23.0. You can specify a custom version if needed:
use ;
// Using default v23.0
let config = new;
// Using custom version (format: vXX.X)
let config = new_with_version;
// Client with custom version
let client = new_with_version;
Note: Facebook guarantees each API version for at least 2 years. Always use the latest stable version when possible.
Usage Examples
Manual Login Flow
Step 1: Generate Login URL
Build the Facebook OAuth login URL (can be done on frontend or backend):
use ;
```rust
use ;
Step 2: Handle Login Response
After successful login, extract tokens or handle errors:
use ;
async
Step 3: Server-Side Token Verification
Verify access tokens or exchange authorization codes on your server:
use ;
// Verify an access token
async
// Exchange authorization code for access token
async
Working with Facebook Pages
Get user's pages and manage page content:
use ;
async
Publishing to Facebook Pages
Create posts, upload photos, and publish videos:
use ;
async
Instagram Business API
Access Instagram business accounts and media:
use ;
async
API Coverage
This crate currently supports:
Authentication & Tokens
- ✅ OAuth login flow with customizable scopes
- ✅ Authorization code exchange
- ✅ Access token verification
- ✅ Short-lived and long-lived tokens
- ✅ Token inspection and debugging
User & Accounts API
- ✅ Get user profile information
- ✅ List user's managed pages
- ✅ Page access token management
Facebook Pages API
- ✅ Publish posts to pages
- ✅ Upload photos to pages
- ✅ Upload videos to pages
- ✅ Page feed management
- ✅ Search functionality
Instagram Business API
- ✅ Instagram Business Account access
- ✅ Media publishing and management
- ✅ Hashtag search
- ✅ Media insights
Other Features
- ✅ Batch API requests
- ✅ Custom API version support
- ✅ Error handling with typed errors
Roadmap (v0.1.x)
- OAuth login dialog and redirect URL handling
- Login response parsing
- Authorization code exchange for access tokens
- JSON response handling
- Access token inspection
- Token storage and login status tracking
- Canceled login handling
- Identity confirmation
- Permission checking
- Re-requesting declined permissions
- User logout functionality
- App uninstall detection
- User data deletion request handling
Error Handling
The crate uses strongly-typed errors through the ClientErr
enum:
use ;
async
Examples
Check out the examples directory for more detailed usage examples, including:
- Complete OAuth flow implementation
- Instagram integration
- Page management
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Setup
# Clone the repository
# Run tests
# Build documentation
# Run examples (requires Facebook App credentials)
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Facebook for Developers - Official API documentation
- Built with ❤️ using Rust
Support
Publishing to Crates.io
This crate is ready for publication to crates.io. When published, users will be able to install it with:
[]
= "0.1.0"
To publish (for maintainers):
# Ensure all tests pass
# Check the package
# Publish to crates.io
Related Projects
- facebook-graph-api - Alternative Facebook API client
- social-media-api - Multi-platform social media API
Note: This is an unofficial library and is not affiliated with Meta Platforms, Inc.