Guides
Getting started

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:

text
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):

PersonaUserWhat happens
adminAnaBusiness Manager admin, with accounts A, B and C and both Pages (default)
no_accountsBrunoNo ad accounts and no Business Manager
no_businessCarlaSees account A through /me/adaccounts, but /me/businesses comes back empty
declinesAnaUnchecked permissions come back as declined in /me/permissions
unavailableAnaThe 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

bash
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>'
json
{ "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.

ErrorCode
Unknown client_id101
Wrong client_secret1
No code100
Malformed or expired code100 / 36007
redirect_uri different from the dialog's100 / 36008
Code already used100 / 36009
unavailable persona or oauth chaos2, is_transient: true, HTTP 500

3. Long-lived token

bash
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

bash
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:

bash
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:

bash
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.

CaseCodeHow to trigger
No token104Omit the token
Unknown token190Any string
Expired token190 / 463token.expire action or advance the clock 60 days
App removed190 / 458DELETE /me/permissions or token.revoke action
Password changed190 / 460token.password_changed action
No permission200A token without ads_management, for example

See also Errors and the Get token reference.