How to use the facebookads.objects.AdGroup.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 / adgroup.py View on Github external
# _DOC close [ADGROUP_CREATE_TRACKING_APP_INSTALLS]
adgroup.remote_delete()

object_story_id = fixtures.create_post(
    message=fixtures.unique_name('Test Post '))['id']

post_id = string.split(object_story_id, '_')[1]

# _DOC open [ADGROUP_CREATE_TRACKING_POST_LIKES]
# _DOC vars [ad_account_id:s, ad_set_id, creative_id, object_story_id, page_id]
from facebookads.objects import AdGroup

adgroup = AdGroup(parent_id=ad_account_id)
adgroup[AdGroup.Field.name] = 'test'
adgroup[AdGroup.Field.campaign_id] = ad_set_id
adgroup[AdGroup.Field.creative] = {
    'object_story_id': object_story_id
}
adgroup[AdGroup.Field.tracking_specs] = {
    'action.type': 'like',
    'post': post_id,
    'post.wall': page_id
}
adgroup.remote_create()
# _DOC close [ADGROUP_CREATE_TRACKING_POST_LIKES]
adgroup.remote_delete()


# _DOC open [ADGROUP_CREATE_TRACKING_LIKE_MENTIONS]
# _DOC vars [ad_account_id:s, ad_set_id, creative_id, post_id, page_id]
from facebookads.objects import AdGroup
github facebook / facebook-python-business-sdk / examples / docs / template.py View on Github external
'''

from examples.docs import fixtures

campaign_group_id = fixtures.create_adcampaign().get_id_assured()


#! _DOC open [TEMPLATE]
#! _DOC vars [campaign_group_id]
from facebookads.objects import AdCampaign, AdGroup

ad_campaign = AdCampaign(campaign_group_id)
ad_groups = ad_campaign.get_ad_groups(fields=[AdGroup.Field.name])

for ad_group in ad_groups:
    print(ad_group[AdGroup.Field.name])
#! _DOC close [TEMPLATE]
github facebook / facebook-python-business-sdk / examples / docs / adaccount.py View on Github external
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount, AdCreative

ad_account = AdAccount(fbid=ad_account_id)
ad_account.get_ad_creatives(fields=[AdCreative.Field.object_story_id])
# _DOC close [ADACCOUNT_GET_ADCREATIVES]


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

ad_account = AdAccount(ad_account_id)
ad_groups = ad_account.get_ad_groups(fields=[AdGroup.Field.name])
for ad_group in ad_groups:
    print(ad_group[AdGroup.Field.name])
# _DOC close [ADACCOUNT_GET_ADGROUPS]


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

account = AdAccount(ad_account_id)
params = {
    'adgroup_status': ['ACTIVE', 'PAUSED', 'CAMPAIGN_PAUSED',
                       'CAMPAIGN_GROUP_PAUSED', 'PENDING_REVIEW', 'DISAPPROVED',
                       'PREAPPROVED', 'PENDING_BILLING_INFO', 'ARCHIVED']
}
adgroups = account.get_ad_groups(params=params)
for adgroup in adgroups:
    print(adgroup)
github facebook / facebook-python-business-sdk / examples / docs / template.py View on Github external
- IDs should be defined outside of _DOC blocks so they don't appear into the
    docs
    - Dependencies, like campaigns, should be generated in the fixtures module
'''

from examples.docs import fixtures

campaign_group_id = fixtures.create_adcampaign().get_id_assured()


#! _DOC open [TEMPLATE]
#! _DOC vars [campaign_group_id]
from facebookads.objects import AdCampaign, AdGroup

ad_campaign = AdCampaign(campaign_group_id)
ad_groups = ad_campaign.get_ad_groups(fields=[AdGroup.Field.name])

for ad_group in ad_groups:
    print(ad_group[AdGroup.Field.name])
#! _DOC close [TEMPLATE]
github facebook / facebook-python-business-sdk / examples / docs / fixtures.py View on Github external
def create_adgroup(ad_set=create_adset(), creative=create_creative()):
    adgroup = AdGroup(parent_id=test_config.account_id)
    adgroup[AdGroup.Field.name] = unique_name('My AdGroup')
    adgroup[AdGroup.Field.campaign_id] = ad_set.get_id_assured()
    adgroup[AdGroup.Field.status] = AdGroup.Status.paused
    adgroup[AdGroup.Field.creative] = {
        'creative_id': creative.get_id_assured(),
    }
    adgroup.remote_create()

    atexit.register(remote_delete, adgroup)

    return adgroup
github facebook / facebook-python-business-sdk / examples / docs / fixtures.py View on Github external
def create_adgroup(ad_set=create_adset(), creative=create_creative()):
    adgroup = AdGroup(parent_id=test_config.account_id)
    adgroup[AdGroup.Field.name] = unique_name('My AdGroup')
    adgroup[AdGroup.Field.campaign_id] = ad_set.get_id_assured()
    adgroup[AdGroup.Field.status] = AdGroup.Status.paused
    adgroup[AdGroup.Field.creative] = {
        'creative_id': creative.get_id_assured(),
    }
    adgroup.remote_create()

    atexit.register(remote_delete, adgroup)

    return adgroup
github facebook / facebook-python-business-sdk / examples / docs / adcampaign.py View on Github external
ad_campaign = AdCampaign(campaign_group_id)
ad_groups = ad_campaign.get_ad_groups(fields=[AdGroup.Field.name])

for ad_group in ad_groups:
    print(ad_group[AdGroup.Field.name])
# _DOC close [ADCAMPAIGN_GET_ADGROUPS]


# _DOC open [ADCAMPAIGN_GET_ADGROUPS_WITH_STATUS_ARCHIVED]
# _DOC vars [campaign_group_id]
from facebookads.objects import AdGroup, AdCampaign

adcampaign = AdCampaign(campaign_group_id)
params = {
    AdGroup.Field.status: [AdGroup.Status.archived],
}
adgroups = adcampaign.get_ad_groups(
    fields=[AdGroup.Field.name],
    params=params
)

for ad_group in adgroups:
    print(ad_group[AdGroup.Field.name])
# _DOC close [ADCAMPAIGN_GET_ADGROUPS_WITH_STATUS_ARCHIVED]


# _DOC open [ADCAMPAIGN_CREATE_LOCAL_AWARENESS]
# _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
### Create a creative.
    creative = AdCreative(parent_id=my_account.get_id_assured())
    creative.update({
        AdCreative.Field.title: 'Visit Seattle',
        AdCreative.Field.body: 'Beautiful Puget Sound!',
        AdCreative.Field.object_url: 'http://www.seattle.gov/visiting/',
        AdCreative.Field.image_hash: img.get_hash(),
    })
    creative.remote_create()
    print("**** DONE: Creative created:")
    pp.pprint(creative)

    ### Get excited, we are finally creating an ad!!!
    ad = AdGroup(parent_id=my_account.get_id_assured())
    ad.update({
        AdGroup.Field.name: 'Puget Sound impression ad',
        AdGroup.Field.campaign_id: ad_set.get_id_assured(),
        AdGroup.Field.creative: {
            AdGroup.Field.Creative.creative_id: creative.get_id_assured(),
        },
    })
    ad.remote_create()
    print("**** DONE: Ad created:")
    pp.pprint(ad)
github facebook / facebook-python-business-sdk / examples / docs / adaccount.py View on Github external
# _DOC open [ADACCOUNT_GET_ADCREATIVES]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount, AdCreative

ad_account = AdAccount(fbid=ad_account_id)
ad_account.get_ad_creatives(fields=[AdCreative.Field.object_story_id])
# _DOC close [ADACCOUNT_GET_ADCREATIVES]


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

ad_account = AdAccount(ad_account_id)
ad_groups = ad_account.get_ad_groups(fields=[AdGroup.Field.name])
for ad_group in ad_groups:
    print(ad_group[AdGroup.Field.name])
# _DOC close [ADACCOUNT_GET_ADGROUPS]


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

account = AdAccount(ad_account_id)
params = {
    'adgroup_status': ['ACTIVE', 'PAUSED', 'CAMPAIGN_PAUSED',
                       'CAMPAIGN_GROUP_PAUSED', 'PENDING_REVIEW', 'DISAPPROVED',
                       'PREAPPROVED', 'PENDING_BILLING_INFO', 'ARCHIVED']
}
adgroups = account.get_ad_groups(params=params)
github facebook / facebook-python-business-sdk / examples / docs / adset.py View on Github external
ad_set.remote_create()
print(ad_set)
# _DOC close [ADSET_CREATE_HOMEPAGE]


ad_set_id = fixtures.create_adset().get_id_assured()

# _DOC open [ADSET_GET_ADGROUPS]
# _DOC vars [ad_set_id]
from facebookads.objects import AdSet, AdGroup

ad_set = AdSet(ad_set_id)
ad_group_iter = ad_set.get_ad_groups(fields=[AdGroup.Field.name])
for ad_group in ad_group_iter:
    print(ad_group[AdGroup.Field.name])
# _DOC close [ADSET_GET_ADGROUPS]


ad_set_id = fixtures.create_adset().get_id_assured()

# _DOC open [ADSET_READ_ADCREATIVE]
# _DOC vars [ad_set_id]
from facebookads.objects import AdSet, AdCreative

adset = AdSet(fbid=ad_set_id)
adset.get_ad_creatives([AdCreative.Field.object_story_id])
# _DOC close [ADSET_READ_ADCREATIVE]


campaign_group_id = fixtures.create_adcampaign().get_id_assured()