I'm running into an issue when trying to fetch data from a Facebook ad account via the Marketing API.
- I’m using a long-lived user access token created by the account admin.
- The user associated with the token has full access in Business Manager.
- Previously, the request
/me/adaccountsworked and returned active accounts, but now it returns the error:
{'error': {'message': 'API access blocked.', 'type': 'OAuthException', 'code': 200, 'fbtrace_id': 'ANGfnFiboGN3X77OVXvprlu'}}
Example code causing the error:
import requests
access_token = "..."
url = "https://graph.facebook.com/v23.0/me/adaccounts"
params = {"access_token": access_token}
response = requests.get(url, params=params)
print(response.json())
I also tried fetching dashboard data via /insights for a specific ad account, but get the same error:
import requests, json, pandas as pd
access_token = "..."
ad_id = "act_7167..."
url = f"https://graph.facebook.com/v23.0/{ad_id}/insights"
time_range = json.dumps({"since":"2025-01-01","until":"2025-09-01"})
params = {
"access_token": access_token,
"time_range": time_range,
"level": "ad",
"fields": "date_start,date_stop,spend,impressions,frequency,cpc,ctr",
"breakdowns": "country",
"time_increment": 1
}
response = requests.get(url, params=params)
data = response.json()
if "error" in data:
print("Error:", data["error"])
else:
df = pd.DataFrame(data["data"])
print(df.to_string())
Why does a valid long-lived user token still fail for /me/adaccounts and /insights?