Search code examples
facebookfacebook-graph-apifacebook-ads-apifacebook-marketing-api

Unable to access Facebook Marketing API


I am trying to access Facebook Marketing API. I have created a facebook app and I can get the token from the user(in this case it is me). But when I use it in the Python Facebook Ads SDK. I get this error :

"message": "(#273) This Ads API call requires the user to be admin of the     ad account. User is not admin on ad account <account ID>.

The account is of a client but I am also an admin there.

I have set "Ads API Account Configuration" in Marketing API settings and "Authorized Ad Account IDs" in app's advanced settings. I have tried in Graph API and I am getting same issue. I was able to access it yesterday but it stopped working and I have tried with multiple apps but the issue is same.

The code I am trying is:

import os

from facebookads import FacebookAdsApi
from facebookads import objects

app_id = os.getenv("APP_ID")
app_secret = os.getenv("APP_SECRET")
access_token =  data['accessToken']  # data is a dictionary with accessToken
FacebookAdsApi.init(app_id, app_secret, access_token)
me = objects.AdUser(fbid='me')
my_accounts = list(me.get_ad_accounts())
print(my_accounts)
account = my_accounts[0]
account.remote_read(fields=[objects.AdAccount.Field.amount_spent])

Solution

  • I was getting the error because my Facebook ads payment failed.