Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create_adset(campaign=create_adcampaign()):
adset = AdSet(parent_id=test_config.account_id)
adset[AdSet.Field.name] = unique_name('Test Adset')
adset[AdSet.Field.campaign_group_id] = campaign.get_id()
adset[AdSet.Field.targeting] = {
'geo_locations': {
'countries': ['US']
}
}
adset[AdSet.Field.optimization_goal] = AdSet.OptimizationGoal.impressions
adset[AdSet.Field.billing_event] = AdSet.BillingEvent.impressions
adset[AdSet.Field.bid_amount] = 100
adset[AdSet.Field.daily_budget] = 1000
adset.remote_create()
atexit.register(remote_delete, adset)
return adset
# _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]
from facebookads.objects import AdAccount, AdSet
account = AdAccount(ad_account_id)
adsets = account.get_ad_sets(fields=[AdSet.Field.name])
for adset in adsets:
print(adset[AdSet.Field.name])
# _DOC close [ADACCOUNT_GET_ADSETS]
# _DOC open [ADACCOUNT_GET_ADUSERS]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount, AdUser
account = AdAccount(ad_account_id)
users = account.get_ad_users()
for user in users:
print(user[AdUser.Field.id])
# _DOC close [ADACCOUNT_GET_ADUSERS]
},
}).get_id()
ad_place_page_set_id = fixtures.create_ad_place_page_set().get_id()
# _DOC oncall [pruno]
# _DOC open [ADSET_CREATE_DLA]
# _DOC vars [campaign_id, ad_account_id:s, ad_place_page_set_id]
from facebookads.objects import AdSet
adset = AdSet(parent_id=ad_account_id)
adset.update({
AdSet.Field.name: 'Local Awareness Ad Set',
AdSet.Field.promoted_object: {
'place_page_set_id': ad_place_page_set_id,
},
AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
AdSet.Field.bid_amount: 2,
AdSet.Field.daily_budget: 1000,
AdSet.Field.campaign_id: campaign_id,
AdSet.Field.targeting: {
'geo_locations': {
'custom_locations': [
{
'latitude': 37.48327,
'longitude': -122.15033,
'radius': 1,
},
{
'latitude': 40.73050,
'longitude': -73.99157,
'radius': 1,
AdSet.Field.configured_status: [
'PENDING', 'ACTIVE', 'PAUSED', 'PENDING_REVIEW',
'DISAPPROVED', 'PREAPPROVED', 'PENDING_BILLING_INFO',
'CAMPAIGN_PAUSED', 'CAMPAIGN_GROUP_PAUSED', 'ARCHIVED'
],
}
else:
params = {'limit': limit}
account = AdAccount(account_id)
ad_sets = account.get_ad_sets(
fields=[
AdSet.Field.id,
AdSet.Field.campaign_id,
AdSet.Field.name,
AdSet.Field.configured_status,
AdSet.Field.targeting,
],
params=params
)
cache = {}
count = 0
results = []
for ad_set in ad_sets:
if count >= limit:
break
count += 1
result = {}
result['id'] = ad_set['id']
result['name'] = ad_set['name']
logger.error(ad_set)
campaign_id = fixtures.create_campaign({
Campaign.Field.objective: Campaign.Objective.local_awareness,
Campaign.Field.promoted_object: {
'page_id': page_id,
},
}).get_id()
ad_place_page_set_id = fixtures.create_ad_place_page_set().get_id()
# _DOC oncall [pruno]
# _DOC open [ADSET_CREATE_DLA]
# _DOC vars [campaign_id, ad_account_id:s, ad_place_page_set_id]
from facebookads.objects import AdSet
adset = AdSet(parent_id=ad_account_id)
adset.update({
AdSet.Field.name: 'Local Awareness Ad Set',
AdSet.Field.promoted_object: {
'place_page_set_id': ad_place_page_set_id,
},
AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
AdSet.Field.bid_amount: 2,
AdSet.Field.daily_budget: 1000,
AdSet.Field.campaign_id: campaign_id,
AdSet.Field.targeting: {
'geo_locations': {
'custom_locations': [
{
'latitude': 37.48327,
'longitude': -122.15033,
'radius': 1,
},
adset[AdSet.Field.name] = 'Product Catalog Sales Adset'
adset[AdSet.Field.bid_amount] = 3000
adset[AdSet.Field.billing_event] = AdSet.BillingEvent.impressions
adset[AdSet.Field.optimization_goal] = \
AdSet.OptimizationGoal.offsite_conversions
adset[AdSet.Field.daily_budget] = 15000
adset[AdSet.Field.campaign_id] = campaign_id
adset[AdSet.Field.targeting] = {
TargetingSpecsField.geo_locations: {
TargetingSpecsField.countries: ['US'],
},
TargetingSpecsField.dynamic_audience_ids: [
dynamic_audience_id,
],
}
adset[AdSet.Field.promoted_object] = {
'product_set_id': product_set_id,
}
adset.remote_create()
# _DOC close [ADSET_CREATE_PRODUCT_CATALOG_SALES]
adset.remote_delete()
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]
from facebookads.objects import AdAccount, AdSet
account = AdAccount(ad_account_id)
adsets = account.get_ad_sets(fields=[AdSet.Field.name])
for adset in adsets:
print(adset[AdSet.Field.name])
# _DOC close [ADACCOUNT_GET_ADSETS]
# _DOC open [ADACCOUNT_GET_ADUSERS]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount, AdUser
account = AdAccount(ad_account_id)
users = account.get_ad_users()
for user in users:
print(user[AdUser.Field.id])
# _DOC close [ADACCOUNT_GET_ADUSERS]
# _DOC open [ADACCOUNT_GET_CONNECTION_OBJECTS]
# _DOC vars [ad_account_id:s]
from examples.docs import fixtures
from facebookads import test_config
ad_account_id = test_config.account_id
campaign_id = fixtures.create_campaign().get_id()
product_set_id = fixtures.create_product_set().get_id()
dynamic_audience_id = fixtures.create_product_audience(product_set_id).get_id()
# _DOC open [ADSET_CREATE_PRODUCT_CATALOG_SALES]
# _DOC vars [ad_account_id:s, dynamic_audience_id, campaign_id, product_set_id]
from facebookads.objects import AdSet, TargetingSpecsField
adset = AdSet(parent_id=ad_account_id)
adset[AdSet.Field.name] = 'Product Catalog Sales Adset'
adset[AdSet.Field.bid_amount] = 3000
adset[AdSet.Field.billing_event] = AdSet.BillingEvent.impressions
adset[AdSet.Field.optimization_goal] = \
AdSet.OptimizationGoal.offsite_conversions
adset[AdSet.Field.daily_budget] = 15000
adset[AdSet.Field.campaign_id] = campaign_id
adset[AdSet.Field.targeting] = {
TargetingSpecsField.geo_locations: {
TargetingSpecsField.countries: ['US'],
},
TargetingSpecsField.dynamic_audience_ids: [
dynamic_audience_id,
],
}
adset[AdSet.Field.promoted_object] = {
'product_set_id': product_set_id,
country = rate_cards[0][RateCard.Field.country]
rate = rate_cards[0][RateCard.Field.rate]
impressions = 5000
lifetime_budget = str(rate * 5000)
end_date = int(time.time() + 12 * 3600)
ad_set = AdSet(parent_id=ad_account_id)
ad_set.update({
AdSet.Field.name: 'Adset Homepage Ads',
AdSet.Field.campaign_group_id: campaign_group_id,
AdSet.Field.lifetime_budget: lifetime_budget,
AdSet.Field.lifetime_imps: impressions,
AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
AdSet.Field.bid_amount: 100,
AdSet.Field.targeting: {
TargetingSpecsField.page_types: ['logout'],
TargetingSpecsField.geo_locations: {
'countries': [country],
}
},
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()
ad_account_id = test_config.account_id
page_id = test_config.page_id
connections_id = page_id
campaign_group_id = fixtures.create_adcampaign().get_id_assured()
ad_set_id = fixtures.create_adset().get_id_assured()
product_catalog_id = test_config.product_catalog_id
product_set_id = test_config.product_set_id
# _DOC open [ADSET_CREATE]
# _DOC vars [ad_account_id:s, campaign_group_id]
from facebookads.objects import AdSet, TargetingSpecsField
adset = AdSet(parent_id=ad_account_id)
adset.update({
AdSet.Field.name: 'My Ad Set',
AdSet.Field.campaign_group_id: campaign_group_id,
AdSet.Field.daily_budget: 1000,
AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
AdSet.Field.bid_amount: 2,
AdSet.Field.targeting: {
TargetingSpecsField.geo_locations: {
'countries': ['US'],
},
},
AdSet.Field.status: AdSet.Status.paused,
})
adset.remote_create()
print(adset)
# _DOC close [ADSET_CREATE]