How to use the facebookads.FacebookAdsApi function in facebookads

To help you get started, we’ve selected a few facebookads examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xiaowan / pyadmin / library / RPCClient.py View on Github external
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
github facebook / facebook-python-business-sdk / examples / create_ad.py View on Github external
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',
github facebook / facebook-python-business-sdk / examples / create_ad.py View on Github external
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,
    })
github facebook / facebook-python-business-sdk / examples / docs / fixtures.py View on Github external
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)