UNPKG

@yaring/n8n-nodes-meta

Version:

N8N node for publishing content to Facebook, Instagram, and Threads with access token authentication. Supports text posts, photos, videos, Reels, carousels, and stories.

436 lines (338 loc) 13.2 kB
![Banner image](https://user-images.githubusercontent.com/10284570/173569848-c624317f-42b1-45a6-ab09-f0ea3c247648.png) # n8n-nodes-facebook-instagram-threads This is an n8n community node that lets you create and publish content to Facebook, Instagram, and Threads using access token authentication. This node supports publishing text posts, photos, videos, Reels, carousels, and stories across all three Meta platforms with comprehensive configuration options. [n8n](https://n8n.io/) is a [fair-code licensed](https://docs.n8n.io/reference/license/) workflow automation platform. ## Table of Contents - [Installation](#installation) - [Prerequisites](#prerequisites) - [Getting Access Token](#getting-access-token) - [Operations](#operations) - [Media Format Requirements](#media-format-requirements) - [Authentication](#authentication) - [Usage Examples](#usage-examples) - [Error Handling](#error-handling) - [Troubleshooting](#troubleshooting) - [Version History](#version-history) ## Installation Follow the [installation guide](https://docs.n8n.io/integrations/community-nodes/installation/) in the n8n community nodes documentation. ### Manual Installation 1. Install the package in your n8n installation: ```bash npm install @yaring/n8n-nodes-meta ``` 2. Restart your n8n instance. ### Docker Installation Add the package to your n8n Docker container by modifying your docker-compose file or Dockerfile: ```dockerfile RUN npm install -g @yaring/n8n-nodes-meta ``` ## Prerequisites Before using this node, you need: 1. **Facebook Developer Account**: Sign up at [developers.facebook.com](https://developers.facebook.com) 2. **Facebook App**: Create a new app in the Facebook Developer Console 3. **Access Token**: Generate access token with required permissions 4. **Business Verification**: Some features require business verification 5. **Page/Instagram Account**: Connected Facebook Page and/or Instagram Business Account 6. **Threads Account**: Professional Threads account linked to Instagram ## Getting Access Token ### Method 1: Facebook Graph API Explorer (Recommended for Testing) 1. Go to [Facebook Graph API Explorer](https://developers.facebook.com/tools/explorer) 2. Select your app from the dropdown 3. Click "Generate Access Token" 4. Select required permissions: - `pages_manage_posts` - Publish to Facebook Pages - `pages_read_engagement` - Read Page information - `instagram_basic` - Basic Instagram access - `instagram_content_publish` - Publish to Instagram - `publish_to_groups` - Publish to Facebook Groups - `threads_basic` - Basic Threads access - `threads_content_publish` - Publish to Threads 5. Generate and copy the access token ### Method 2: App Dashboard (Production) 1. In your Facebook App dashboard, go to "Tools" → "Access Token Tool" 2. Generate a User Access Token or Page Access Token 3. For long-lived tokens, exchange short-lived tokens using the API 4. Copy the access token ### Token Types - **User Access Token**: For posting to user's own profile and pages they manage - **Page Access Token**: For posting specifically to a Facebook page - **App Access Token**: For app-level operations (not recommended for posting) ## Operations ### Facebook Operations #### Create Text Post - **Target Types**: Page, Group, User Profile - **Required**: Target ID, Message - **API Endpoint**: `/{target-id}/feed` - **Supported**: All text formatting, mentions, hashtags #### Create Photo Post - **Target Types**: Page, Group, User Profile - **Required**: Target ID, Photo URL - **Optional**: Caption - **API Endpoint**: `/{target-id}/photos` - **Supported**: JPEG, PNG formats #### Create Video Post - **Target Types**: Page, Group, User Profile - **Required**: Target ID, Video URL - **Optional**: Video Description - **API Endpoint**: `/{target-id}/videos` - **Supported**: MP4, MOV formats #### Create Link Post - **Target Types**: Page, Group, User Profile - **Required**: Target ID, Link URL - **Optional**: Link Message - **API Endpoint**: `/{target-id}/feed` - **Supported**: Automatic link preview generation ### Instagram Operations #### Create Photo Post - **Required**: Instagram Business Account ID, Image URL - **Optional**: Caption - **API Process**: Create container → Publish - **Supported**: JPEG, PNG formats #### Create Video Post - **Required**: Instagram Business Account ID, Video URL - **Optional**: Caption - **API Process**: Create container → Publish - **Supported**: MP4 format, feed videos (square/landscape) #### Create Reels - **Required**: Instagram Business Account ID, Reels Video URL - **Optional**: Caption, Cover Image URL - **API Process**: Create container → Publish - **Supported**: MP4 format, vertical orientation (9:16 aspect ratio) #### Create Carousel Post - **Required**: Instagram Business Account ID, Media Items (multiple photos/videos) - **Optional**: Caption - **API Process**: Create individual containers → Create carousel → Publish - **Supported**: Mix of photos and videos (up to 10 items) #### Create Story - **Required**: Instagram Business Account ID, Story Media URL, Media Type - **Optional**: None - **API Process**: Create container → Publish - **Supported**: JPEG, PNG for images; MP4 for videos ### Threads Operations #### Create Text Post - **Required**: Threads User ID, Text - **Optional**: None - **API Process**: Create post → Publish - **Supported**: Plain text, mentions, hashtags #### Create Photo Post - **Required**: Threads User ID, Image URL - **Optional**: Text - **API Process**: Create post → Publish - **Supported**: JPEG, PNG formats #### Create Video Post - **Required**: Threads User ID, Video URL - **Optional**: Text - **API Process**: Create post → Publish - **Supported**: MP4 format ## Media Format Requirements ### Images #### Facebook - **Formats**: JPEG, PNG - **Max Size**: 4MB - **Min Resolution**: 200x200px - **Max Resolution**: 2048x2048px - **Aspect Ratio**: Any (square recommended for best display) #### Instagram Feed/Carousel - **Formats**: JPEG, PNG - **Max Size**: 8MB - **Min Resolution**: 320px (any dimension) - **Max Resolution**: 1440x1800px - **Aspect Ratio**: 1.91:1 to 4:5 (landscape to portrait) #### Instagram Stories - **Formats**: JPEG, PNG - **Max Size**: 8MB - **Resolution**: 1080x1920px (recommended) - **Aspect Ratio**: 9:16 (vertical) #### Threads - **Formats**: JPEG, PNG - **Max Size**: 8MB - **Min Resolution**: 320px (any dimension) - **Aspect Ratio**: 1:1 to 4:5 (square to portrait) ### Videos #### Facebook - **Formats**: MP4, MOV - **Max Size**: 4GB - **Max Duration**: 240 minutes - **Min Resolution**: 720p - **Recommended**: H.264 codec, AAC audio #### Instagram Feed Video - **Formats**: MP4 - **Max Size**: 1GB - **Max Duration**: 60 seconds - **Min Resolution**: 720p - **Aspect Ratio**: 1.91:1 to 4:5 - **Recommended**: H.264 codec, AAC audio #### Instagram Reels - **Formats**: MP4 - **Max Size**: 1GB - **Max Duration**: 90 seconds - **Min Resolution**: 720p - **Aspect Ratio**: 9:16 (vertical) - **Recommended**: H.264 codec, AAC audio, 30fps #### Instagram Stories Video - **Formats**: MP4 - **Max Size**: 1GB - **Max Duration**: 15 seconds - **Resolution**: 1080x1920px - **Aspect Ratio**: 9:16 (vertical) #### Threads - **Formats**: MP4 - **Max Size**: 1GB - **Max Duration**: 5 minutes - **Min Resolution**: 720p - **Recommended**: H.264 codec, AAC audio ## Authentication This node uses access token authentication: 1. **Create Credentials**: In n8n, create new "Facebook, Instagram & Threads API" credentials 2. **Enter Access Token**: Paste your access token from Facebook Graph API Explorer or App Dashboard 3. **Set API Version**: Choose API version (default: v23.0) 4. **Test Connection**: n8n will automatically test the token validity ### Required Permissions Your access token must include these permissions: - `pages_manage_posts` - Publish to Facebook Pages - `pages_read_engagement` - Read Page information - `instagram_basic` - Basic Instagram access - `instagram_content_publish` - Publish to Instagram - `publish_to_groups` - Publish to Facebook Groups - `user_posts` - Post to user timeline (if available) - `threads_basic` - Basic Threads access - `threads_content_publish` - Publish to Threads ## Usage Examples ### Example 1: Post to Facebook Page ```json { "resource": "facebook", "operation": "createTextPost", "targetType": "page", "targetId": "1234567890123456", "message": "Hello from n8n! 🚀" } ``` ### Example 2: Instagram Photo with Caption ```json { "resource": "instagram", "operation": "createPhotoPost", "instagramBusinessAccountId": "1234567890123456", "imageUrl": "https://example.com/image.jpg", "caption": "Check out this amazing photo! #n8n #automation" } ``` ### Example 3: Instagram Reels ```json { "resource": "instagram", "operation": "createReels", "instagramBusinessAccountId": "1234567890123456", "reelsVideoUrl": "https://example.com/video.mp4", "reelsCaption": "Amazing automation with n8n! ⚡ #n8n #reels #automation", "coverImageUrl": "https://example.com/cover.jpg" } ``` ### Example 4: Instagram Carousel ```json { "resource": "instagram", "operation": "createCarouselPost", "instagramBusinessAccountId": "1234567890123456", "mediaItems": { "mediaItem": [ { "mediaType": "IMAGE", "mediaUrl": "https://example.com/image1.jpg" }, { "mediaType": "VIDEO", "mediaUrl": "https://example.com/video1.mp4" } ] }, "carouselCaption": "Swipe to see more! ➡️" } ``` ### Example 5: Threads Text Post ```json { "resource": "threads", "operation": "createTextPost", "threadsUserId": "1234567890123456", "text": "Just automated my social media posting with @n8n 🤖" } ``` ## Getting Account IDs ### Facebook Page ID 1. Go to your Facebook Page 2. Click "About" → "Page Info" 3. Scroll down to find "Page ID" 4. Or use Graph API: `https://graph.facebook.com/v23.0/me/accounts` ### Instagram Business Account ID 1. Use Facebook Graph API Explorer: `/{page-id}?fields=instagram_business_account` 2. Or check in your Facebook Page settings under "Instagram" 3. Or use Graph API: `https://graph.facebook.com/v23.0/{page-id}?fields=instagram_business_account` ### Threads User ID 1. Use Facebook Graph API Explorer: `/{instagram-account-id}?fields=threads_id` 2. Requires Instagram account connected to Threads 3. Or use Graph API: `https://graph.facebook.com/v23.0/{instagram-account-id}?fields=threads_id` ## Error Handling The node includes comprehensive error handling: - **Authentication Errors**: Clear messages for invalid/expired tokens - **API Rate Limits**: Detailed rate limit information and retry suggestions - **Media Validation**: Specific errors for unsupported formats or sizes - **Permission Errors**: Detailed explanations for missing permissions - **Facebook Error Codes**: Full Facebook error details with trace IDs ### Common Error Codes - **190**: Invalid OAuth access token - **200**: Missing required permissions - **100**: Invalid parameter (check media URLs and formats) - **368**: Media violates content policy - **80001**: Instagram account not found or not business account ## Troubleshooting ### Common Issues #### "Invalid OAuth access token" - **Cause**: Expired or invalid access token - **Solution**: Generate new access token from Facebook Graph API Explorer #### "Insufficient permissions" - **Cause**: Missing required permissions - **Solution**: Generate token with all required scopes listed above #### "Media could not be processed" - **Cause**: Unsupported media format or size - **Solution**: Check media requirements section and convert to supported format #### "Page not found" - **Cause**: Incorrect Page/Account ID - **Solution**: Verify IDs using Facebook Graph API Explorer #### "Rate limit exceeded" - **Cause**: Too many API calls in short time - **Solution**: Implement delays between calls or use different access token ### Debug Mode Enable debug mode to see detailed API responses: ```bash export N8N_LOG_LEVEL=debug ``` ## API Versions This node supports: - **Facebook Graph API**: v23.0 (configurable, compatible with v18.0+) - **Instagram Graph API**: Latest version - **Threads API**: Latest version ## Rate Limits Meta APIs have rate limits per access token: - **Facebook**: 200 calls per hour per user - **Instagram**: 240 calls per hour per user - **Threads**: 1000 calls per 24 hours per user The node provides detailed error information when rate limits are exceeded. ## Support For support and questions: - **GitHub Issues**: [Report bugs and feature requests](https://github.com/YARlabs/n8n-nodes-meta/issues) - **n8n Community**: [Community forum](https://community.n8n.io) - **Documentation**: [Meta for Developers](https://developers.facebook.com/docs) ## Version History ### v0.0.1 - Initial release - Facebook, Instagram, and Threads support - Access token authentication - Instagram Reels support - All major content types supported - Comprehensive error handling - Detailed media format validation ## License [MIT](https://github.com/YARlabs/n8n-nodes-meta/blob/master/LICENSE.md)