# How to Revoke an AI Agent's Access to Facebook and Protect Your Account from Lockout

> AI Release · @ai_release1 · https://ai-release.org/guides/kak-otozvat-dostup-ii-agenta-k-facebook-i-zaschitit-akk_en.html

## TL;DR

- Time to complete: 15–20 minutes
- Difficulty: Intermediate
- You will need: a desktop browser with an active Facebook session, admin rights on the Meta app your agent uses, `curl` and `jq` (command-line HTTP client and JSON parser), access to the machine or container where the agent runs, and write access to its environment variables or secret store.

## Requirements and setup
![Illustration: Requirements and setup](https://ai-release.org/guides/img/kak-otozvat-dostup-ii-agenta-k-facebook-i-zaschitit-akk-en-1.jpg?v=1794992579)


- **OS:** any Linux/macOS shell for the commands below; Windows users can run the same `curl` calls in PowerShell 7+ or WSL. On older PowerShell, `curl` is an alias for `Invoke-WebRequest`, so call `curl.exe` explicitly.
- **Packages:** `curl` (any current build) and `jq` (JSON filter). Install with `sudo apt install curl jq` or `brew install curl jq`. Verify with `jq --version` — it must print a version string.
- **Access:** you must be able to log in to the Facebook account the agent acts for, and to the Meta developer app that issued the agent's credentials. Without app-admin rights you can still revoke from the user side, but you cannot rotate the app secret.
- **Credentials at hand:** the agent's *user access token* (the string that lets it act as you), your app ID, and your app secret. Store them in a password manager, not in a shell history file.
- **A place to write down findings:** a plain text file such as `revoke-audit.txt` with one line per app, token and permission.

Two terms used below. **Access token** — a long string that proves "this program is allowed to act for this account"; whoever holds it, can post. **Graph API** — Meta's HTTP interface for reading and writing Facebook data; every agent call goes through it.

Before anything else, map what is holding a token. Most leaks are not in Facebook at all:

| Where the token lives | Typical symptom | Where to look |
|---|---|---|
| Shell `export` / `.env` file | Survives reboot of your laptop | `grep -r "access_token" ~/.env ./agent` |
| Container environment | Old value after you rotated | `docker inspect <container> \| grep -i token` |
| Secret manager entry | Agent reads stale version | your vault's version history |
| Agent config (tools list) | Tool still enabled after revoke | the agent's tool/permission file |
| Notebook / script copy | Forgotten one-off run | `grep -rl "EAA" ~/projects` |

## Step 1. Inventory every app, token and permission the agent holds

**What to do:** list all apps with access to the account, then ask the Graph API which permissions the agent's token actually carries.

**Why:** you cannot revoke what you have not named. A token can hold a dozen scopes (permissions), and revoking the wrong one leaves the posting scope alive.

**How to check:** first the human-readable list. In Facebook open **Settings & privacy → Settings → Apps and Websites**. Record every entry under **Active**, then open **Expired** and **Removed** — a revoked app that still appears as Active was never actually revoked. Menu wording changes between releases; if a label differs, use the search box inside Settings.

Next, ask the API directly:

```bash
export FB_USER_TOKEN="<agent-user-access-token>"
export API_VERSION="<graph-api-version>"   # e.g. the version shown in your app dashboard
curl -s -G "https://graph.facebook.com/${API_VERSION}/me/permissions" \
  -d "access_token=${FB_USER_TOKEN}" | jq -r '.data[] | [.permission, .status] | @tsv'
```

**Example output** (tab-separated, granted scopes only):

```
public_profile	granted
email	granted
pages_show_list	granted
pages_manage_posts	granted
```

Count the granted scopes and write that number into `revoke-audit.txt`. If the call returns `{"error":{...}}` instead of a `data` array, the token is already dead — skip to Step 3.

**Example:** an agent built only to draft captions does not need `pages_manage_posts`. Anything beyond read scopes is a candidate for removal, which is the least-privilege principle: give the program the smallest set of permissions that still lets it finish its job.

## Step 2. Revoke access in Facebook and in the agent runtime
![Illustration: Step 2. Revoke access in Facebook and in the agent runtime](https://ai-release.org/guides/img/kak-otozvat-dostup-ii-agenta-k-facebook-i-zaschitit-akk-en-2.jpg?v=1794992586)


**What to do:** revoke permission by permission through the API, delete the app entry in Facebook, then remove every stored copy of the token from the agent's environment.

**Why:** revoking on the Facebook side stops new calls, but a cached token in a container will keep retrying and generating failed requests. Repeated failures are what pushes an account toward temporary restrictions.

Start with the narrow case — drop one permission and keep the rest:

```bash
curl -s -X DELETE \
  "https://graph.facebook.com/${API_VERSION}/me/permissions/pages_manage_posts?access_token=${FB_USER_TOKEN}" | jq
```

**Expected output:**

```json
{
  "success": true
}
```

Then revoke everything the token holds, which is the step that actually disconnects the agent:

```bash
curl -s -X DELETE \
  "https://graph.facebook.com/${API_VERSION}/me/permissions?access_token=${FB_USER_TOKEN}" | jq
```

Why this works: the DELETE call invalidates the granted scopes server-side, so the token can no longer perform those actions even if a copy survives on disk.

Now remove the app from the account: **Settings & privacy → Settings → Apps and Websites → Active → select the app → Remove**. Confirm with the **Remove** button in the dialog.

Finally, purge the runtime. Example of the environment file the agent reads at start:

```bash
# before
FB_USER_TOKEN=EAA...
FB_APP_SECRET=...

# after — remove both lines, then rotate the app secret in the app dashboard
```

Commands to stop stale copies:

```bash
docker compose down && docker compose up -d      # container env is re-read on start
kubectl rollout restart deployment/<agent-name>  # Kubernetes equivalent
unset FB_USER_TOKEN                              # current shell
```

**How to check:** run `docker inspect <container> | grep -i -c "EAA"` — it must print `0`. Run `grep -r "EAA" ./agent ~/.env` — no matches. If you use a secret manager, confirm the old version is destroyed, not just superseded. If the agent was granted access through a Business Manager system user rather than your personal profile, revoke the system user's token and asset assignment in Business Manager too; those tokens are not listed under Apps and Websites. The exact screen depends on your Business Manager role — check Meta's documentation for "system user tokens" before you touch it.

For a broader threat model around credentials in agent pipelines, see [AI agent security: protecting your data during automation](https://ai-release.org/guides/bezopasnost-ii-agentov-kak-zaschitit-dannye-i-izbezhat.html?utm_source=tg&utm_medium=channel&utm_campaign=guide_inline&utm_content=guide_to_guide), and for keeping agent configs in a predictable layout, [ICM in practice: a folder structure that keeps agents manageable](https://ai-release.org/guides/icm-praktika-struktura-papok-agenta.html?utm_source=tg&utm_medium=channel&utm_campaign=guide_inline&utm_content=guide_to_guide).

## Step 3. Verify the revoke and harden the account against restrictions
![Illustration: Step 3. Verify the revoke and harden the account against restrictions](https://ai-release.org/guides/img/kak-otozvat-dostup-ii-agenta-k-facebook-i-zaschitit-akk-en-3.jpg?v=1794992595)


**What to do:** prove the token is powerless, then close the behaviours that trigger Facebook's automated security checks.

**Why:** "I clicked Remove" is not evidence. Verification is a second API call that must come back empty.

**How to check:** re-run the permissions query.

```bash
curl -s -G "https://graph.facebook.com/${API_VERSION}/me/permissions" \
  -d "access_token=${FB_USER_TOKEN}" | jq -r '.data[]? | "\(.permission)\t\(.status)"'
```

**Expected result:** no output at all, or rows with status `declined`. Any row still saying `granted` means the revoke did not apply to that scope — repeat the DELETE for it.

Inspect the token itself:

```bash
curl -s -G "https://graph.facebook.com/${API_VERSION}/debug_token" \
  --data-urlencode "input_token=${FB_USER_TOKEN}" \
  --data-urlencode "access_token=<app-id>|<app-secret>" \
  | jq '.data | {is_valid, scopes, expires_at}'
```

**Example output:**

```json
{
  "is_valid": true,
  "scopes": [],
  "expires_at": 0
}
```

`is_valid: true` with an empty `scopes` array is a normal, successful end state: the token string exists but carries no permissions. If `scopes` is not empty, go back to Step 2.

Account-protection checklist — each item removes a known trigger for automated blocks:

- [ ] The agent authenticates only through OAuth with a scoped token; it never types your password or a 2FA code (automated logins are a classic restriction trigger).
- [ ] One Meta app per agent, so a single bad loop does not poison everything else.
- [ ] Two-factor authentication is on, and the recovery email and phone number are current — otherwise you cannot pass a security check later.
- [ ] Rate limits are handled with exponential backoff on `(#4)` and `(#17)` errors instead of instant retries.
- [ ] Only one running instance per token; duplicate agents double your request volume invisibly.
- [ ] Apps and Websites is reviewed monthly; the audit file gets a new dated line each time.
- [ ] The agent holds no posting scope it does not actively use.

## Troubleshooting

**Problem. The agent keeps posting after you revoked access.**
- Error: `(#190) Error validating access token: The session has been invalidated because the user changed their password or Facebook has changed the session for security reasons.`
- Cause: a copy of the token is still in a running process, a `.env` file, or a secret manager cache; the process retries with the old value.
- Solution: stop the process (`docker compose down` or `kubectl scale deployment/<agent-name> --replicas=0`), delete every file matched by `grep -rl "EAA" .`, destroy the old secret version, rotate the app secret in the app dashboard, then restart and re-run the Step 3 check.

**Problem. Requests fail with a permission error and the agent retries in a tight loop.**
- Error: `(#200) The user hasn't authorized the application to perform this action`
- Cause: the agent's tool list still declares an action (for example a page-publishing tool) whose permission you just revoked. Each retry is a new failed call, and the rising error rate is what gets an account flagged.
- Solution: disable the task, delete the tool entry from the agent config, redeploy, and confirm the log stays silent for one full cycle before re-enabling anything.

**Problem. Call volume suddenly explodes.**
- Error: `(#4) Application request limit reached`
- Cause: two agent instances share one app credential, or a queue is draining without backoff.
- Solution: keep a single instance (`docker ps` should show one), process the queue with a delay between calls, and cache responses you already fetched. Meta's exact per-app ceiling is not a fixed public number — check the documentation for the current limits of your app tier.

## Summary and next steps

You now hold a written inventory of every app and permission, a token that returns an empty scope list, and an agent runtime with no stored copy of it. Next, add the monthly Apps and Websites review to your calendar and, if you plan to build more agents, read [How to turn a regular LLM chat into a full-fledged AI agent](https://ai-release.org/guides/kak-prevratit-obychnyy-chat-s-llm-v-polnotsennogo-ai-ag.html?utm_source=tg&utm_medium=channel&utm_campaign=guide_inline&utm_content=guide_to_guide) so the permission model is designed in from the start.

## FAQ

**How do I remove an app's access to my Facebook account?**
Settings & privacy → Settings → Apps and Websites → Active, select the app, click Remove. Confirm afterwards with the `me/permissions` call in Step 3 — the list must be empty.

**Does revoking access delete posts the agent already published?**
No. Revoking a token removes permission to act; content already created stays on the page and must be deleted manually.

**Will my Facebook account get blocked for using an AI agent?**
Access through OAuth with a scoped token is the supported path. Restrictions usually follow automated password logins, ignored rate-limit errors, or many duplicate instances — the checklist in Step 3 targets exactly those.

**How do I know if an old token is still valid?**
Call `debug_token` with the app access token as shown in Step 3. An empty `scopes` array means it can no longer do anything; `is_valid: false` means it is gone entirely.
