An AI-powered agent that automatically generates text and images, then posts to Facebook and Instagram.
- AI Content Generation: Uses OpenAI GPT-4 for text and DALL-E 3 for images
- Multi-Platform Publishing: Posts to Facebook Pages and Instagram Business accounts
- OAuth Token Management: Secure token storage with automatic refresh
- Rate Limiting: Built-in rate limiting to respect API limits
Before using this agent, you need:
-
Meta Developer Account & App
- See Meta Setup Guide for detailed instructions
- Create at developers.facebook.com
- Create a Meta App with Facebook Login product
- Add required permissions:
pages_manage_posts,instagram_content_publish, etc.
-
Facebook Page linked to an Instagram Business Account
-
OpenAI API Key (for AI content generation)
- Get from platform.openai.com
-
Cloudinary Account (for image hosting - required for Instagram)
- Free tier available at cloudinary.com
# Clone the repository
git clone <your-repo-url>
cd auto_posting
# Install dependencies
pip install -e .- Copy the example environment file:
cp .env.example .env- Edit
.envwith your credentials:
# Meta (Facebook/Instagram)
META_APP_ID=your_app_id
META_APP_SECRET=your_app_secret
META_PAGE_ID=your_facebook_page_id
META_INSTAGRAM_ACCOUNT_ID=your_instagram_business_account_id
# OpenAI
OPENAI_API_KEY=your_openai_api_key
# Cloudinary
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret- Run OAuth setup to authenticate with Meta:
python scripts/setup_oauth.py- Save the generated
ENCRYPTION_KEYto your.envfile.
python -m auto_posting.main verify# Post to both Facebook and Instagram
python -m auto_posting.main post "Your topic here"
# Post to Facebook only
python -m auto_posting.main post "Your topic" --facebook
# Post to Instagram only
python -m auto_posting.main post "Your topic" --instagram
# Post without AI-generated image
python -m auto_posting.main post "Your topic" --no-imagepython scripts/test_post.pyauto_posting/
├── .env # Your credentials (not in git)
├── .env.example # Template for credentials
├── pyproject.toml # Project dependencies
├── README.md # This file
├── scripts/
│ ├── setup_oauth.py # OAuth authentication setup
│ └── test_post.py # Test posting without AI
└── src/auto_posting/
├── main.py # CLI entry point
├── config.py # Settings management
├── auth/
│ └── token_manager.py # OAuth token handling
├── content/
│ ├── text_generator.py # OpenAI GPT-4 integration
│ └── image_generator.py # OpenAI DALL-E 3 integration
├── publishers/
│ ├── facebook.py # Facebook Graph API
│ ├── instagram.py # Instagram Graph API
│ └── media_uploader.py # Cloudinary image hosting
└── utils/
├── rate_limiter.py # API rate limiting
└── retry.py # Exponential backoff
| Limit | Value |
|---|---|
| API calls | 200/user/hour |
| Posts | 100/account/24 hours |
| Instagram hashtags | 5 max per post |
| Carousel images | 10 max |
Add the required permissions in Meta Developer Dashboard:
- Go to your app → Use cases
- Click "Customize" on each use case
- Add:
pages_manage_posts,instagram_content_publish, etc.
Add credits at platform.openai.com/settings/organization/billing
Instagram requires publicly accessible HTTPS URLs. Make sure Cloudinary is configured correctly.
MIT