Meta Graph API access tokens authorize calls to Facebook and Instagram data through graph.facebook.com. User tokens come from Facebook Login or the Graph API Explorer and last about one to two hours, or about 60 days once exchanged for a long-lived token; Page tokens from a long-lived user token do not expire. System user tokens from Meta Business Manager suit servers and can be set to never expire, and the app secret signs everything, so it must stay on your server.
Meta Graph API key types
| Type | Prefix | Secret? | Scope | Expiry |
|---|---|---|---|---|
| User access token Meta warns lifetimes may change without warning or end early, for example when the user changes their password. | — | Yes | The permissions the user granted to your Meta app | Short-lived tokens last about one to two hours; long-lived tokens last about 60 days |
| Page access token Requested from /{user-id}/accounts; they are still invalidated if the user loses their role on the Page. | — | Yes | Read, write and modify data for one Facebook Page the user has a role on | Page tokens obtained from a long-lived user token have no expiration date |
| System user access token Meant for automated server-to-server work on ad objects and Pages. | — | Yes | The scopes chosen for a system user in Business Manager, such as `ads_management` or `pages_read_engagement` | Either never expires or is valid for 60 days and must be refreshed |
| App access token and app secret The app access token can be sent as {app-id}|{app-secret}, which exposes the secret itself. | — | Yes | Read and modify app settings; the app secret also signs `appsecret_proof` and token exchanges | Lasts until the app secret is reset |
How to create a Meta Graph API key
- Create or open your app in the Meta App Dashboard at
developers.facebook.com. - Open the Graph API Explorer (
developers.facebook.com/tools/explorer) with your app selected. - Click Generate Access Token and approve the Facebook Login dialog to get a user access token.
- Add the permissions you need from Add a Permission, then click Generate Access Token again.
- For a server, exchange the token on your backend for a long-lived one, or generate a system user token in Business Manager.
Open Meta Graph API's key settings
Limiting what the key can do
Graph API tokens carry only the permissions the user or system user approved, so request the smallest set of permissions, such as pages_show_list instead of broad management permissions. Turn on Require App Secret under App Settings → Advanced → Security so every server call must include appsecret_proof, a SHA-256 HMAC of the access token keyed with the app secret; a stolen token alone is then useless without the secret. Time-stamped proofs expire after 5 minutes. Use the Access Token Tool to list your tokens and inspect their scopes and expiry.
How to rotate a Meta Graph API key
- For user tokens, exchange a valid short-lived token on your server with
grant_type=fb_exchange_tokento get a new long-lived token before the old one lapses. - For expiring system user tokens, refresh them before the 60-day validity ends.
- For the app secret, reset it in the App Dashboard under Basic → App Secret and update your servers.
An expired user token cannot be exchanged, so the user must log in again. Make the exchange call from your server, because it sends the app secret.
How to revoke a Meta Graph API key
- Revoke a compromised system user token with the
oauth/revokeendpoint, sendingrevoke_token,client_id,client_secretandaccess_token. - Reset the app secret under Basic → App Secret if it was exposed; this also stops
{app-id}|{app-secret}tokens. - Check the Access Token Tool afterwards to confirm which tokens remain and what they can do.
If your Meta Graph API key leaked
- Revoke the exposed system user token with
oauth/revoke, or have the affected user log in again for a fresh token. - Reset the app secret if it, or an app access token, appeared anywhere outside your server.
- Turn on Require App Secret so tokens cannot be used without
appsecret_proof. - Review Page and ad account activity for actions you did not take.
Things that catch people out
- Subcode 460 means the user changed their password, which invalidates their tokens even inside the 60-day window.
- Subcode 492 on a Page token means the user behind the token no longer has a suitable role on the Page.
- Never put the app secret or an app access token in client code or app binaries; Meta says to use them only server to server.
- Meta's official MCP server (
mcp.facebook.com/ads) covers ads management, not the whole Graph API.
Common Meta Graph API authentication errors
OAuthException code 190 - Access token has expired
The access token has expired, been revoked or is otherwise invalid; subcode 463 means expired and 467 means invalid.
OAuthException code 102 - API Session
The login status or token has expired, been revoked or is otherwise invalid.
OAuthException code 10 - API Permission Denied
The permission the call needs was not granted or has been removed.
Using your Meta Graph API key with AI agents
A coding agent that can read your .env file or your shell history can read the key, and anything in its context can end up in logs, transcripts or a prompt-injected request. The safer pattern is to keep the key in a credential broker that performs the authenticated step for the agent and hands back only the result.
BotPassword works this way. For a Meta Graph API key, these intents fit:
| Intent | What BotPassword does |
|---|---|
run_with | Runs a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output. |
http_request | Makes an authenticated API call after checking the destination against the hosts this key may be sent to. The response comes back with credential-shaped values redacted, and one that holds the key itself is refused. |
Meta Graph API also publishes its own MCP server. Whatever server the agent uses, keep the credential it authenticates with out of the agent's context.
Set it up in your agent: Aider · Amp · Claude Code · Claude Desktop · Cline · OpenAI Codex CLI · all agents
Frequently asked questions
How do I get a Facebook Graph API access token?
Open the Graph API Explorer at developers.facebook.com/tools/explorer, select your app, click Generate Access Token and approve the login dialog. That gives a short-lived user token for testing.
How long do Meta Graph API access tokens last?
Short-lived user tokens last about one to two hours and long-lived ones about 60 days. Page tokens from a long-lived user token have no expiration, and system user tokens can be set to never expire or to 60 days.
How do I get a long-lived access token?
On your server, call oauth/access_token with grant_type=fb_exchange_token, your app ID, app secret and the short-lived token. The result lasts about 60 days.
Why did my long-lived Meta access token stop working before 60 days?
Meta says token lifetimes can change without warning or end early. A password change (subcode 460), a security checkpoint (459) or losing a Page role (492) all invalidate tokens, so handle error 190 by getting a new token.
Is there an official Meta MCP server for AI agents?
Meta hosts an Ads MCP Server at mcp.facebook.com/ads for managing ads, reporting and catalogs from an AI agent. For other Graph API work, give the agent a narrowly scoped system user token instead of a personal user token.
Can an AI agent use my Meta Graph API key without seeing it?
Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a .env file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with run_with, http_request, so the agent gets the result and never the value.