Exchange the Meta code
POST /api/marketing/oauth/exchangeValidates 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.
Request body
Section titled “Request body”| Field | Type | Description | |
|---|---|---|---|
code | string | required | code that Meta returned in the redirect. |
redirect_uri | string | required | The SAME redirect_uri used to request the URL. Meta compares it and rejects the exchange if it does not match exactly. |
state | string | required | The signed state issued by GET /oauth/url. |
Responses
Section titled “Responses”| Status | Description | Schema |
|---|---|---|
200 | — | — |
400 | The user did not grant ads_management (or the state is not valid). | MissingPermissionResponseDto |
Example
Section titled “Example”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" }'MissingPermissionResponseDto
Section titled “MissingPermissionResponseDto”| Field | Type | Description | |
|---|---|---|---|
error | missing_permission | required | — |
message | string | required | — |
missing | string[] | optional | Permissions the user did not grant in Meta’s dialog. Example: ["ads_management"]. |