Skip to content

Exchange the Meta code

POST /api/marketing/oauth/exchange

Validates the state, exchanges the code for a long-lived token and registers one account for each ad account the user granted access to, with status available. The client then chooses which ones to activate. Requires the marketing:manage scope.

FieldTypeDescription
codestringrequiredcode that Meta returned in the redirect.
redirect_uristringrequiredThe SAME redirect_uri used to request the URL. Meta compares it and rejects the exchange if it does not match exactly.
statestringrequiredThe signed state issued by GET /oauth/url.
StatusDescriptionSchema
200——
400The user did not grant ads_management (or the state is not valid).MissingPermissionResponseDto
Terminal window
curl -X POST https://api.neike.dev/api/marketing/oauth/exchange \
-H "x-neike-api-key: whk_live_…" \
-H "Content-Type: application/json" \
-d '{
"code": "string",
"redirect_uri": "string",
"state": "string"
}'
FieldTypeDescription
errormissing_permissionrequired—
messagestringrequired—
missingstring[]optionalPermissions the user did not grant in Meta’s dialog. Example: ["ads_management"].