NameError: name 'adobjects' is not defined

513 views Asked by At

I have installed facebook_business with pip:

pip install facebook_business

I believe my credentials are correct because I can print the list of campaigns id like this:

import sys
sys.path.append('C:/users/user/anaconda3/lib/site-packages') 
sys.path.append('C:/users/user/anaconda3/lib/site-packages/facebook_business-8.0.2-py3.7.egg/')

from facebook_business.api import FacebookAdsApi
from facebook_business.adobjects.adaccount import AdAccount

my_app_id = 'XXX'
my_app_secret = 'XXX'
my_access_token = 'XXX'
FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token)

my_account = AdAccount('act_XXX')
campaigns = my_account.get_campaigns()
print(campaigns)

result:

[<Campaign> {"id": "xxx"}, <Campaign> {"id": "xxx"}]

However when trying to use adobjects, for example:

my_account = adobjects.AdAccount('act_xxx')

I get this error:

NameError: name 'adobjects' is not defined
2

There are 2 answers

0
A Caradonna On

I imported like this and it works now:

from facebook_business.adobjects.abstractcrudobject import  AbstractCrudObject
0
Sprizgola On

I think that you should just import the object you need from adobjects and then use it, like:

from facebook_business.adobjects.adaccount import AdAccount
account = AdAccount("act_****")
campaigns = account.get_campaigns()