Overview
Meta Ads Copilot uses social-cli, an open-source CLI tool, to authenticate with Meta’s Marketing API. No API keys, no app secrets in your.env file — just a simple OAuth flow.
social-cli is maintained by @vishalgojha and handles token management, refresh logic, and API versioning automatically.
Prerequisites
You need:- A Facebook account with access to your ad account
- Admin or Analyst role on the ad account (for reading data)
- Advertiser role if you want the agent to take actions (pause ads, adjust budgets)
Installation
Quick Authentication (Recommended)
This is the fastest way to get started. social-cli uses Meta’s test app for authentication.Authorize in your browser
A browser window opens automatically. If it doesn’t, copy the URL from the terminal.You’ll see Meta’s OAuth screen asking for permissions:
- Read ad account data
- Access ad insights
- Manage ads (optional)
Grant permissions
Click Continue and Allow. The browser will redirect and show “Authentication successful.”
Advanced: Using Your Own Meta App
If you want full control or need a production app, create your own Meta developer application.Why use your own app?
- Higher rate limits (test apps have lower quotas)
- Custom app name shows in user consent screen
- Required for production deployments
- Ability to use System User tokens (for automation)
Create a Meta App
Go to Meta for Developers
Visit developers.facebook.com/apps and click Create App.
Fill in app details
- App Name: “My Ad Manager” (or your brand name)
- Contact Email: Your email
- Business Account: Select your business (or create one)
Add Marketing API product
From your app dashboard:
- Click Add Products in the left sidebar
- Find Marketing API
- Click Set Up
Get your App ID and Secret
Go to Settings → Basic in the left sidebar.Copy:
- App ID (e.g.,
123456789012345) - App Secret (click Show, then copy)
Required Scopes
Meta API permissions are controlled by scopes. Request only what you need.Read Campaign DataAllows:
- List campaigns, ad sets, and ads
- Read configurations and settings
- View targeting, placements, and budgets
Read Performance MetricsAllows:
- Access ad insights (spend, impressions, clicks, conversions)
- Breakdown by age, gender, placement, device
- Custom date ranges and attribution windows
Manage Campaigns and AdsAllows:
- Pause and resume ads/ad sets/campaigns
- Update budgets and bids
- Create new campaigns (if using ad-upload skill)
- Delete ads
Monitoring Only vs. Full Control
Monitoring Only (Read-Only):- Daily performance checks
- Bleeder and winner reports
- Creative fatigue detection
- Budget efficiency analysis
- Pause underperforming ads
- Resume winning ads
- Adjust budgets
- Upload new creatives
Set Your Default Ad Account
After authentication, tell social-cli which ad account to use.Override Per Command
You can override the default account for specific reports:Token Management
social-cli handles token lifecycle automatically:- Tokens expire after 60 days (standard Meta user token)
- social-cli auto-refreshes before expiration
- Refresh tokens are stored securely in
~/.social-cli/
Check Token Status
Manual Token Refresh
If you encounter auth errors, refresh manually:Re-authenticate
If your token is invalid or you need to change scopes:Logout
Revoke access and clear stored tokens:Environment Variables
Meta Ads Copilot uses minimal environment variables. Authentication is handled by social-cli, not.env files.
Optional: Default Ad Account
Set in.env (or export in your shell):
.env
.env.example
The example file is intentionally minimal:.env.example
.env. Everything is managed securely by social-cli.
Troubleshooting
”social: command not found”
Cause: social-cli not installed or not in PATH. Fix:Authentication fails / browser doesn’t open
Cause: Popup blockers or headless environment. Fix:- Copy the URL from the terminal
- Paste into a browser manually
- Complete the OAuth flow
- The CLI will detect the callback
”No ad accounts found”
Cause: Your Facebook user doesn’t have access to any ad accounts. Fix:- Go to business.facebook.com
- Check if you’re added to the Business Manager
- Verify you have a role on the ad account (Admin or Analyst)
- If you own the ad account but it’s not in Business Manager, add it:
- Business Settings → Accounts → Ad Accounts → Add → Add an Ad Account
”Error: (#200) Requires ads_read permission”
Cause: You didn’t grant the required scopes during login. Fix: Re-authenticate with correct scopes:“Token expired” error
Cause: Token expired and auto-refresh failed. Fix:Rate limit errors
Cause: Hit Meta’s API rate limits (common with test apps). Fix:- Wait 5-10 minutes
- Retry the command
- If using a test app, create your own production app for higher limits
”Invalid OAuth access token”
Cause: Token was revoked, user changed password, or app permissions changed. Fix: Re-authenticate:Check Everything (Diagnostics)
Run the built-in health check:- social-cli installation
- Authentication status
- Token validity
- API connectivity
- Ad account access
Advanced: System User Tokens (For Automation)
If you’re running Meta Ads Copilot on a server or in production, use a System User token instead of a personal token.Why System Users?
- Tokens don’t expire after 60 days
- Not tied to a personal Facebook account
- More stable for cron jobs and automation
- Recommended for production deployments
Create a System User
Go to Business Settings
Create the user
- Name: “Meta Ads Copilot Bot”
- Role: Admin (if you need
ads_managementscope) or Analyst (read-only)
Assign ad account access
Click on the system user, then Assign Assets.Add your ad account with appropriate permissions:
- View performance (for read-only)
- Manage campaigns (for full control)
Generate a token
Click Generate New Token.Select your app and permissions:
ads_readread_insightsads_management(if needed)
Security Best Practices
-
Never commit tokens to Git
- social-cli stores tokens in
~/.social-cli/(not your repo) - If using system user tokens, store in environment variables or secrets manager
- social-cli stores tokens in
-
Use minimal scopes
- Only request
ads_managementif you need action capabilities - Start with
ads_read,read_insightsfor monitoring-only
- Only request
-
Rotate tokens periodically
- Even though system user tokens don’t expire, rotate them every 90 days
- User tokens auto-refresh, but re-authenticate if there’s suspicious activity
-
Use System Users in production
- Don’t rely on personal accounts for automated systems
- System Users are more stable and auditable
-
Monitor access logs
- Check Meta’s audit logs in Business Settings
- Review who has access to your app and ad accounts
Related
- Benchmarks — Configure performance thresholds
- Automation — Schedule daily checks with cron
- Daily Check — Your first authenticated report