Search code examples
pythonfacebookaccess-tokenfacebook-ads-apifacebook-marketing-api

Facebook Ads API - Object with ID


Im trying to query the costs of my facebook campaigns with a python script. For now i think the sample code they generate for you is ok, but im getting this error:

Unsupported get request. Object with ID 'XXX' does not exist, cannot be loaded due to missing permissions, or does not support this operation. And i cant figure out what im doing wrong. For the access token im generating one on the Marketing API Configuration.

Any idea what i skipped or did wrong?

The app has the ad account added to it from both the app configuration and the business configuration: App business

Here i get the access token: Access token

Here is the sample code im using:

from facebookads.adobjects.adaccount import AdAccount
from facebookads.adobjects.adsinsights import AdsInsights
from facebookads.api import FacebookAdsApi

access_token = 'xxx'
ad_account_id = 'xxx'
app_secret = 'xxx'
FacebookAdsApi.init(access_token=access_token)

fields = [
    'today_spend',
]
params = {
    'time_range': {'since':'2017-07-03','until':'2017-08-02'},
    'filtering': [],
    'level': 'campaign',
    'breakdowns': [],
}
print AdAccount(ad_account_id).get_insights(
    fields=fields,
    params=params,
)

Solution

  • The solution was really dumb, i was missing 'act_' before the ad_account_id number.