Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
pp.pprint(img) # The image hash can be found using img[AdImage.Field.hash]
### 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)
AdSet.Field.end_time: end_date,
})
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]
import string
ad_account_id = test_config.account_id
app_id = test_config.app_id
page_id = test_config.page_id
ad_set_id = fixtures.create_adset().get_id_assured()
ad_group_id = fixtures.create_adgroup().get_id_assured()
creative_id = fixtures.create_creative().get_id_assured()
image_hash = fixtures.create_image().get_hash()
# _DOC open [ADGROUP_CREATE]
# _DOC vars [ad_account_id:s, ad_set_id, creative_id]
from facebookads.objects import AdGroup
adgroup = AdGroup(parent_id=ad_account_id)
adgroup[AdGroup.Field.name] = 'My AdGroup'
adgroup[AdGroup.Field.campaign_id] = ad_set_id
adgroup[AdGroup.Field.status] = AdGroup.Status.paused
adgroup[AdGroup.Field.creative] = {
'creative_id': creative_id,
}
adgroup.remote_create()
# _DOC close [ADGROUP_CREATE]
adgroup.remote_delete()
# _DOC open [ADGROUP_CREATE_TRACKING_APP_INSTALLS]
# _DOC vars [ad_account_id:s, ad_set_id, creative_id, app_id]
from facebookads.objects import AdGroup
adgroup = AdGroup(parent_id=ad_account_id)
adgroup[AdGroup.Field.name] = 'My AdGroup'
adgroup[AdGroup.Field.campaign_id] = ad_set_id
adgroup[AdGroup.Field.status] = AdGroup.Status.paused
adgroup[AdGroup.Field.creative] = {
'creative_id': creative_id,
}
adgroup.remote_create()
# _DOC close [ADGROUP_CREATE]
adgroup.remote_delete()
# _DOC open [ADGROUP_CREATE_TRACKING_APP_INSTALLS]
# _DOC vars [ad_account_id:s, ad_set_id, creative_id, app_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] = {
'creative_id': creative_id
}
adgroup[AdGroup.Field.tracking_specs] = {
'action.type': 'app_install',
'application': app_id
}
adgroup.remote_create()
# _DOC close [ADGROUP_CREATE_TRACKING_APP_INSTALLS]
adgroup.remote_delete()
object_story_id = fixtures.create_post(
message=fixtures.unique_name('Test Post '))['id']