Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def call(self, access_token='', method='', path=(), params={}):
caller = FacebookAdsApi.init(self.app_id, self.app_secret, access_token)
try:
return caller.call(method, path, params).json()
except FacebookRequestError as fberror:
return fberror.body()
except Exception as es:
raise es
pp = pprint.PrettyPrinter(indent=4)
this_dir = os.path.dirname(__file__)
config_filename = os.path.join(this_dir, 'config.json')
config_file = open(config_filename)
config = json.load(config_file)
config_file.close()
### Setup session and api objects
session = FacebookSession(
config['app_id'],
config['app_secret'],
config['access_token'],
)
api = FacebookAdsApi(session)
if __name__ == '__main__':
FacebookAdsApi.set_default_api(api)
print('\n\n\n********** Ad Creation example. **********\n')
### Setup user and read the object from the server
me = AdUser(fbid='me')
### Get first account connected to the user
my_account = me.get_ad_account()
### Create a Campaign
campaign = AdCampaign(parent_id=my_account.get_id_assured())
campaign.update({
AdCampaign.Field.name: 'Seattle Ad Campaign',
config_filename = os.path.join(this_dir, 'config.json')
config_file = open(config_filename)
config = json.load(config_file)
config_file.close()
### Setup session and api objects
session = FacebookSession(
config['app_id'],
config['app_secret'],
config['access_token'],
)
api = FacebookAdsApi(session)
if __name__ == '__main__':
FacebookAdsApi.set_default_api(api)
print('\n\n\n********** Ad Creation example. **********\n')
### Setup user and read the object from the server
me = AdUser(fbid='me')
### Get first account connected to the user
my_account = me.get_ad_account()
### Create a Campaign
campaign = AdCampaign(parent_id=my_account.get_id_assured())
campaign.update({
AdCampaign.Field.name: 'Seattle Ad Campaign',
AdCampaign.Field.objective: AdCampaign.Objective.website_clicks,
AdCampaign.Field.status: AdCampaign.Status.paused,
})
def get_page_api():
page_token = get_page_access_token()
session = FacebookSession(test_config.app_id,
test_config.app_secret,
page_token)
return FacebookAdsApi(session)