How to use the facebookads.objects.AdCampaign.Field 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 facebook / facebook-python-business-sdk / examples / docs / adaccount.py View on Github external
account[AdAccount.Field.name] = 'New Name'
account.remote_update()
# _DOC close [ADACCOUNT_UPDATE]
account[AdAccount.Field.name] = old_name
account.remote_update()

# _DOC open [ADACCOUNT_GET_ADCAMPAIGNS]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount, AdCampaign

account = AdAccount(ad_account_id)
campaigns = account.get_ad_campaigns(fields=[
    AdCampaign.Field.name,
])
for campaign in campaigns:
    print(campaign[AdCampaign.Field.name])
# _DOC close [ADACCOUNT_GET_ADCAMPAIGNS]


# _DOC open [ADACCOUNT_UPDATE_SPEND_CAP]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount

account = AdAccount(ad_account_id)

account[AdAccount.Field.spend_cap] = 10000
account.remote_update()
# _DOC close [ADACCOUNT_UPDATE_SPEND_CAP]


# _DOC open [ADACCOUNT_GET_ADSETS]
# _DOC vars [ad_account_id:s]
github facebook / facebook-python-business-sdk / examples / docs / adset.py View on Github external
# _DOC open [ADSET_GET_INSIGHTS_LEVEL_ADGROUP]
# _DOC vars [ad_set_id]
from facebookads.objects import AdSet, Insights

adset = AdSet(fbid=ad_set_id)
params = {
    'level': Insights.Level.adgroup
}

stats = adset.get_insights(params=params)
print(stats)
# _DOC close [ADSET_GET_INSIGHTS_LEVEL_ADGROUP]

params = {
    AdCampaign.Field.objective: AdCampaign.Objective.product_catalog_sales,
    AdCampaign.Field.promoted_object: {'product_catalog_id': product_catalog_id}
}

campaign_group_id = fixtures.create_adcampaign(params).get_id_assured()

# _DOC open [ADSET_CREATE_DYNAMIC_PROSPECTIING]
# _DOC vars [ad_account_id:s, product_set_id, campaign_group_id]
from facebookads.objects import AdSet, TargetingSpecsField

adset = AdSet(parent_id=ad_account_id)
adset[AdSet.Field.name] = 'Case 1 Adset'
adset[AdSet.Field.bid_amount] = 3000
adset[AdSet.Field.billing_event] = AdSet.BillingEvent.link_clicks
adset[AdSet.Field.optimization_goal] = AdSet.OptimizationGoal.link_clicks
adset[AdSet.Field.status] = AdSet.Status.active
adset[AdSet.Field.daily_budget] = 15000
github facebook / facebook-python-business-sdk / examples / docs / fixtures.py View on Github external
def create_adcampaign(params={}):
    campaign = AdCampaign(parent_id=test_config.account_id)
    campaign[AdCampaign.Field.name] = unique_name('Test Campaign')
    campaign[AdCampaign.Field.buying_type] = AdCampaign.BuyingType.auction
    campaign[AdCampaign.Field.objective] = AdCampaign.Objective.none
    campaign[AdCampaign.Field.status] = AdCampaign.Status.paused

    campaign.update(params)
    campaign.remote_create()

    atexit.register(remote_delete, campaign)

    return campaign
github facebook / facebook-python-business-sdk / examples / create_ad.py View on Github external
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,
    })
    campaign.remote_create()
    print("**** DONE: Campaign created:")
    pp.pprint(campaign)

    ### Create an Ad Set
    ad_set = AdSet(parent_id=my_account.get_id_assured())
    ad_set.update({
        AdSet.Field.name: 'Puget Sound AdSet',
        AdSet.Field.status: AdSet.Status.paused,
        AdSet.Field.bid_type: AdSet.BidType.cpm,  # Bidding for impressions
        AdSet.Field.bid_info: {
            AdSet.Field.BidInfo.impressions: 500,   # $5 per 1000 impression
        },
github facebook / facebook-python-business-sdk / examples / docs / adaccount.py View on Github external
account = AdAccount(ad_account_id)

account[AdAccount.Field.name] = 'New Name'
account.remote_update()
# _DOC close [ADACCOUNT_UPDATE]
account[AdAccount.Field.name] = old_name
account.remote_update()

# _DOC open [ADACCOUNT_GET_ADCAMPAIGNS]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount, AdCampaign

account = AdAccount(ad_account_id)
campaigns = account.get_ad_campaigns(fields=[
    AdCampaign.Field.name,
])
for campaign in campaigns:
    print(campaign[AdCampaign.Field.name])
# _DOC close [ADACCOUNT_GET_ADCAMPAIGNS]


# _DOC open [ADACCOUNT_UPDATE_SPEND_CAP]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount

account = AdAccount(ad_account_id)

account[AdAccount.Field.spend_cap] = 10000
account.remote_update()
# _DOC close [ADACCOUNT_UPDATE_SPEND_CAP]
github facebook / facebook-python-business-sdk / examples / docs / fixtures.py View on Github external
def create_adcampaign(params={}):
    campaign = AdCampaign(parent_id=test_config.account_id)
    campaign[AdCampaign.Field.name] = unique_name('Test Campaign')
    campaign[AdCampaign.Field.buying_type] = AdCampaign.BuyingType.auction
    campaign[AdCampaign.Field.objective] = AdCampaign.Objective.none
    campaign[AdCampaign.Field.status] = AdCampaign.Status.paused

    campaign.update(params)
    campaign.remote_create()

    atexit.register(remote_delete, campaign)

    return campaign
github facebook / facebook-python-business-sdk / examples / docs / adset.py View on Github external
'geo_locations': {
            'countries': ['US'],
        }
    },
    AdSet.Field.start_time: int(time.time()),
    AdSet.Field.campaign_group_id: campaign_group_id
})
adset.remote_create()

print(adset)
# _DOC close [ADSET_CREATE_CPC_PROMOTING_PAGE]
adset.remote_delete()


params = {
    AdCampaign.Field.buying_type: AdCampaign.BuyingType.fixed_cpm
}

campaign_group_id = fixtures.create_adcampaign(params).get_id_assured()

# _DOC open [ADSET_CREATE_HOMEPAGE]
# _DOC vars [ad_account_id:s, campaign_group_id]
import time
from facebookads.objects import (
    AdAccount,
    AdSet,
    RateCard,
    TargetingSpecsField
)

ad_account = AdAccount(ad_account_id)
rate_cards = ad_account.get_rate_cards()
github facebook / facebook-python-business-sdk / examples / docs / adcampaign.py View on Github external
from facebookads import test_config
from examples.docs import fixtures
import time

ad_account_id = test_config.account_id
campaign_group_id = fixtures.create_adcampaign().get_id()
product_catalog_id = test_config.product_catalog_id
product_set_id = test_config.product_set_id

# _DOC open [ADCAMPAIGN_CREATE_HOMEPAGE]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdCampaign

campaign = AdCampaign(parent_id=ad_account_id)
campaign.update({
    AdCampaign.Field.name: 'Homepage Campaign',
    AdCampaign.Field.buying_type: AdCampaign.BuyingType.fixed_cpm,
    AdCampaign.Field.objective: AdCampaign.Objective.none,
    AdCampaign.Field.status: AdCampaign.Status.paused,
})

campaign.remote_create()
print(campaign)
# _DOC close [ADCAMPAIGN_CREATE_HOMEPAGE]
campaign.remote_delete()


# _DOC open [ADCAMPAIGN_CREATE_VIDEO_VIEWS]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdCampaign

campaign = AdCampaign(parent_id=ad_account_id)
github facebook / facebook-python-business-sdk / examples / create_ad.py View on Github external
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,
    })
    campaign.remote_create()
    print("**** DONE: Campaign created:")
    pp.pprint(campaign)

    ### Create an Ad Set
    ad_set = AdSet(parent_id=my_account.get_id_assured())
    ad_set.update({
        AdSet.Field.name: 'Puget Sound AdSet',
        AdSet.Field.status: AdSet.Status.paused,
        AdSet.Field.bid_type: AdSet.BidType.cpm,  # Bidding for impressions
        AdSet.Field.bid_info: {
            AdSet.Field.BidInfo.impressions: 500,   # $5 per 1000 impression
        },
        AdSet.Field.daily_budget: 3600,  # $36.00
github facebook / facebook-python-business-sdk / examples / docs / adcampaign.py View on Github external
while async_job['async_percent_completion'] < 100:
    time.sleep(1)
    async_job.remote_read()

print(async_job.get_result())
# _DOC close [ADCAMPAIGN_GET_INSIGHTS_ASYNC]

# _DOC open [ADCAMPAIGN_CREATE_OBJECTIVE_PRODUCT_CATELOG_SALES]
# _DOC vars [ad_account_id:s, product_catalog_id]
from facebookads.objects import AdCampaign

campaign = AdCampaign(parent_id=ad_account_id)
campaign[AdCampaign.Field.name] = 'Product Catalog Sales Campaign Group'
campaign[AdCampaign.Field.status] = AdCampaign.Status.paused
objective = AdCampaign.Objective.product_catalog_sales
campaign[AdCampaign.Field.objective] = objective
campaign[AdCampaign.Field.promoted_object] = {
    'product_catalog_id': product_catalog_id
}

campaign.remote_create()
# _DOC close [ADCAMPAIGN_CREATE_OBJECTIVE_PRODUCT_CATELOG_SALES]
campaign.remote_delete()