Guides
Authentication
Facebook Login in the manual flow, code exchange, long-lived token, app token, appsecret_proof, system user and token errors.
The Marketing API uses Graph access tokens. The path for a server integration is the manual Facebook Login flow: the person authorizes in the dialog, your server exchanges the code for a 60-day user token and uses it on every call.
1. Open the dialog
Send the browser to the login dialog:
https://meta-ads.mimicr.dev/v27.0/dialog/oauth?client_id=<app_id>&redirect_uri=https%3A%2F%2Fapp.example.com%2Fmeta%2Fcallback&state=st-123&response_type=code&scope=ads_read,ads_management,business_management,pages_show_list,pages_read_engagement,pages_manage_ads
With Facebook Login for Business, replace scope with config_id: the permissions and the token type come from the configuration. Configurations are created with the login.config control action (see Sandbox control).
The redirect_uri must be in the app's valid OAuth redirect URIs. In Mimicr, an empty list (the default) accepts any https and localhost URL; to restrict it, use PUT /v1/meta-ads/app with redirect_uris. An unknown client_id shows the "Invalid App ID" page; a redirect_uri outside the list shows "URL blocked".
The Mimicr dialog
The dialog is a hosted page that lets the tester pick a persona, uncheck permissions and choose the ad accounts and Pages the app will see (the granular_scopes):
| Persona | User | What happens |
|---|---|---|
admin | Ana | Business Manager admin, with accounts A, B and C and both Pages (default) |
no_accounts | Bruno | No ad accounts and no Business Manager |
no_business | Carla | Sees account A through /me/adaccounts, but /me/businesses comes back empty |
declines | Ana | Unchecked permissions come back as declined in /me/permissions |
unavailable | Ana | The code exchange fails with a transient error (code 2, HTTP 500) |
Continue redirects to redirect_uri?code=…&state=st-123#_=_. Cancel redirects to redirect_uri?error=access_denied&error_code=200&error_description=Permissions+error&error_reason=user_denied&state=st-123#_=_. The trailing #_=_ is what Facebook appends.
2. Exchange the code
curl --url 'https://meta-ads.mimicr.dev/v27.0/oauth/access_token?client_id=<app_id>&client_secret=<app_secret>&redirect_uri=https%3A%2F%2Fapp.example.com%2Fmeta%2Fcallback&code=<code>'
{ "access_token": "EAA…", "token_type": "bearer", "expires_in": 5183944 }The user token lasts 60 days by the sandbox clock. The code is valid for 10 minutes and only once, and the redirect_uri must be identical to the dialog's. The same parameters also work via POST with a form body.
| Error | Code |
|---|---|
Unknown client_id | 101 |
Wrong client_secret | 1 |
No code | 100 |
| Malformed or expired code | 100 / 36007 |
redirect_uri different from the dialog's | 100 / 36008 |
| Code already used | 100 / 36009 |
unavailable persona or oauth chaos | 2, is_transient: true, HTTP 500 |
3. Long-lived token
curl --url 'https://meta-ads.mimicr.dev/v27.0/oauth/access_token?grant_type=fb_exchange_token&client_id=<app_id>&client_secret=<app_secret>&fb_exchange_token=<token>'
The response has the same format, with a different token string, the same user, permissions and assets, and a fresh 60 days of validity. The old token stays valid until its own expiry. An expired token can't be exchanged (190/463).
4. App token
curl --url 'https://meta-ads.mimicr.dev/v27.0/oauth/access_token?grant_type=client_credentials&client_id=<app_id>&client_secret=<app_secret>'
Returns {"access_token":"<app_id>|<app_secret>","token_type":"bearer"}. The literal string <app_id>|<app_secret> is also accepted as a token. Use it with debug_token and for webhook subscriptions.
Using the token
The token can go in Authorization: Bearer <token> (or OAuth <token>), or as access_token in the query or the body (form or JSON). To check what a token can do:
curl --url 'https://meta-ads.mimicr.dev/v27.0/debug_token?input_token=<token>' \ --header 'Authorization: Bearer <app_id>|<app_secret>'
The response carries scopes, expires_at and granular_scopes, with the ids of the accounts (without act_), Pages and Business Managers each permission covers. /me/permissions lists what was granted and declined; DELETE /me/permissions removes the app and invalidates all of the user's tokens.
appsecret_proof
appsecret_proof is the HMAC-SHA256 of the token with the app secret, in hex:
PROOF=$(printf '%s' "$TOKEN" | openssl dgst -sha256 -hmac "$APP_SECRET" | cut -d' ' -f2) curl --url "https://meta-ads.mimicr.dev/v27.0/me?appsecret_proof=$PROOF" \ --header "Authorization: Bearer $TOKEN"
When present, it's always verified: a wrong proof answers 100 "Invalid appsecret_proof provided in the API argument". The requireAppSecretProof toggle (off by default) makes the proof mandatory for user tokens.
System user
A login configuration with token_type: system_user makes the code exchange return a token without expires_in that never expires (expires_at: 0 in debug_token). Through the control API, POST /v1/meta-ads/token with {"system_user": true} issues one directly.
Token errors
All with HTTP 400, type: "OAuthException" and the header WWW-Authenticate: OAuth "Facebook Platform" "invalid_token" "<message>" on code 190.
| Case | Code | How to trigger |
|---|---|---|
| No token | 104 | Omit the token |
| Unknown token | 190 | Any string |
| Expired token | 190 / 463 | token.expire action or advance the clock 60 days |
| App removed | 190 / 458 | DELETE /me/permissions or token.revoke action |
| Password changed | 190 / 460 | token.password_changed action |
| No permission | 200 | A token without ads_management, for example |