Пример #1
0
    def enable_an_on_adsets(self, adsetids):
        """
        Method that takes a list of ad set ids and enables the audience network
        placement on them. Please note that this method does not perform any
        pre-validation check to see whether the ad set passed  satisfies the
        pre-requisites to have audience network enabled.

        Args:
            adsetids: List of ad set ids on which you want audience network
            enabled. Even if you have just one id, pass it as a list.
        Returns:
            A list of 'ad set id' vs. 'status' mapping with a further 'message'
            node whenever there was a failure to update the audience network.
            Returns an empty list when an empty list or non list element is
            passed.

            status 1 is a success.
            status 0 is a failure.

            Sample response format:
            [
                {'<ad_set_id_1>': {'status': 1}},
                {'<ad_set_id_2>': {'status': 0, 'message': '<exception_msg>'}},
                ...
            ]
        """
        results = []

        # check if adsets is a list
        if type(adsetids) is not list:
            return results

        # go over the list of adset ids
        for adsetid in adsetids:
            try:
                # read ad set info
                adset = AdSet(fbid=adsetid)
                adsetobj = adset.remote_read(fields=[AdSet.Field.targeting])

                # edit targeting spec info for placements
                targetinginfo = copy.deepcopy(adsetobj[AdSet.Field.targeting])
                targetinginfo[TargetingSpecsField.publisher_platforms]. \
                    append('audience_network')

                # update ad set info
                adset.update({AdSet.Field.targeting: targetinginfo})
                adset.remote_update()

                # update result list along with status
                results.append({adsetid: {'status': 1}})

            except FacebookError as e:

                # update result list along with status & message
                results.append({adsetid: {'status': 0, 'message': e.message}})

        return results
def create_adset(campaign_id):
    adset = AdSet(parent_id='act_259842962')
    adset.update({
        AdSet.Field.name: 'My Ad Set',
        AdSet.Field.campaign_id: campaign_id,
        AdSet.Field.daily_budget: 10000,
        AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
        AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
        AdSet.Field.bid_amount: 2,
        AdSet.Field.targeting: {
            Targeting.Field.geo_locations: {
                'countries': ['IN'],
            },
            Targeting.Field.age_min: 20,
            Targeting.Field.age_max: 24
        },
        AdSet.Field.status: AdSet.Status.paused,
    })
    adset.remote_create()
    return adset
Пример #3
0
def create_adset(campaign=None, params={}):
    if campaign is None:
        campaign = create_campaign()

    adset = AdSet(parent_id=test_config.account_id)
    adset[AdSet.Field.name] = unique_name('Test Adset')
    adset[AdSet.Field.campaign_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.update(params)
    adset.remote_create()

    atexit.register(remote_delete, adset)

    return adset
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: campaign_id,
    AdSet.Field.targeting: {
        'geo_locations': {
            'regions': [{
                'key': '3847'
            }],
            'cities': [
                {
                    'key': '2430536',
                    'radius': '12',
                    'distance_unit': 'mile',
                },
            ],
        },
        'genders': [1],
        'relationship_statuses': [2, 3, 4],
        'age_min': 18,
        'age_max': 43,
        'interests': [
            {
                'id': 6003139266461,
                'name': 'Movies',
            },
        ],
    },
})
Пример #5
0
        'days': [0, 1, 2, 3, 4, 5, 6],
    }

    # Attempt 2:
    AdSet.Field.start_time: str(datetime.datetime(year=2017, month=3, day=6, hour=1, minute=36)),
    AdSet.Field.end_time: str(datetime.datetime(year=2017, month=3, day=6, hour=6, minute=0)),
'''

# Update the Adset
my_page_id = '103185246428488'      # Ideas Behind the Web page ID
adset.update({
    AdSet.Field.name: 'Adset Name',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.daily_budget: 200,
    AdSet.Field.promoted_object: {
        'page_id': my_page_id,
    },
    AdSet.Field.campaign_id: campaign_id,
    AdSet.Field.targeting: targeting,
    AdSet.Field.is_autobid: True,
})

# Remotely create the adset
adset.remote_create(params={
    'status': AdSet.Status.active,
})
print("Remotely created the adset")

#### Creating the Ads ########################################################
# The code below was our attempt at creating ads, however, we encountered the
#   error with code 100, subcode 144305, title "Error Loading Image," and
adset = AdSet(parent_id=ad_account_id)
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: campaign_id,
    AdSet.Field.promoted_object: {'page_id': page_id},
    AdSet.Field.targeting: {
        TargetingSpecsField.geo_locations: {
            'countries': ['JP'],
            'regions': [
                {'key': '3886'},
            ],
            'cities': [
                {
                    'key': '2420605',
                    'radius': '10',
                    'distance_unit': 'mile',
                },
            ],
        },
        TargetingSpecsField.genders: [1],
        TargetingSpecsField.age_min: 20,
        TargetingSpecsField.age_max: 24,
        TargetingSpecsField.page_types: ['mobilefeed', 'mobileexternal'],
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
Пример #7
0
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]
adset.remote_delete()



# _DOC open [ADSET_CREATE_APP_CONNECTIONS_TARGETING]
ad_account_id = test_config.account_id
connections_id = test_config.page_id
campaign_id = fixtures.create_campaign().get_id_assured()

# _DOC open [ADSET_CREATE_APP_CONNECTIONS_TARGETING]
# _DOC vars [ad_account_id:s, campaign_id, connections_id]
from facebookads.objects import AdSet, TargetingSpecsField

ad_set = AdSet(parent_id=ad_account_id)
ad_set.update({
    AdSet.Field.name: 'Android Connections Targeting - Ad Set',
    AdSet.Field.campaign_id: campaign_id,
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.post_engagement,
    AdSet.Field.billing_event: AdSet.BillingEvent.post_engagement,
    AdSet.Field.bid_amount: 1500,
    AdSet.Field.daily_budget: 10000,
    AdSet.Field.targeting: {
        TargetingSpecsField.geo_locations: {
            'countries': ['US'],
        },
        TargetingSpecsField.connections: [connections_id],
        TargetingSpecsField.user_os: ['Android'],
    },
})

ad_set.remote_create(params={
    'status': AdSet.Status.paused,
})
print(ad_set)
# _DOC close [ADSET_CREATE_APP_CONNECTIONS_TARGETING]
# _DOC vars [ad_account_id:s, app_id, campaign_id, app_store_url:s]
import time
from facebookads.objects import AdSet

adset = AdSet(parent_id=ad_account_id)
adset.update({
    AdSet.Field.name: 'LifetimeBudgetSet',
    AdSet.Field.campaign_id: campaign_id,
    AdSet.Field.lifetime_budget: 10000,
    AdSet.Field.start_time: int(time.time()),
    AdSet.Field.end_time: int(time.time() + 100000),
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.offsite_conversions,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 500,
    AdSet.Field.promoted_object: {
        'application_id': app_id,
        'object_store_url': app_store_url,
        'custom_event_type': 'ADD_TO_CART',
    },
    AdSet.Field.targeting: {
        'geo_locations': {
            'countries': ['US'],
        },
        'user_os': ['iOS'],
    },
})

adset.remote_create(params={
    'status': AdSet.Status.paused,
})
# _DOC close [ADSET_CREATE_CPA_APP_EVENTS]
adset = AdSet(parent_id=ad_account_id)
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: campaign_id,
    AdSet.Field.targeting: {
        'geo_locations': {
            'countries': ['US'],
        },
        'interests': [
            {
                'id': 6003139266461,
                'name': 'Movies',
            },
            {
                'id': 6003397425735,
                'name': 'Tennis',
            },
            {
                'id': 6003659420716,
                'name': 'Cooking',
            },
        ],
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
# _DOC open [ADSET_CREATE_PLACEMENT_TARGETING]
# _DOC vars [ad_account_id:s, campaign_id]
from facebookads.objects import AdSet

adset = AdSet(parent_id=ad_account_id)
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: campaign_id,
    AdSet.Field.targeting: {
        'geo_locations': {
            'countries': ['US'],
        },
        'page_types': [
            'desktopfeed',
            'rightcolumn',
            'mobilefeed',
            'mobileexternal',
        ],
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
# _DOC close [ADSET_CREATE_PLACEMENT_TARGETING]

adset.remote_delete()
# _DOC vars [ad_account_id:s, campaign_id]
from facebookads.objects import AdSet

adset = AdSet(parent_id=ad_account_id)
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: campaign_id,
    AdSet.Field.targeting: {
        'geo_locations': {
            'countries': ['US'],
        },
        'user_adclusters': [
            {
                'id': 6002714885172,
                'name': 'Cooking',
            },
            {
                'id': 6002714898572,
                'name': 'Small Business Owners',
            },
        ],
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
# _DOC close [ADSET_CREATE_BROAD_CATEGORY_TARGETING]
# _DOC open [ADSET_CREATE_BCT_LOCATION_DEMOGRAPHICS_TARGETING]
# _DOC vars [ad_account_id:s, campaign_id]
from facebookads.objects import AdSet

adset = AdSet(parent_id=ad_account_id)
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: campaign_id,
    AdSet.Field.targeting: {
        'geo_locations': {
            'countries': ['US'],
        },
        'relationship_statuses': [2],
        'user_adclusters': [
            {
                'id': 6002714886772,
                'name': 'Food & Dining',
            },
        ],
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
# _DOC close [ADSET_CREATE_BCT_LOCATION_DEMOGRAPHICS_TARGETING]

adset.remote_delete()
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: campaign_id,
    AdSet.Field.targeting: {
        'geo_locations': {
            'countries': ['US'],
        },
        'age_min': 18,
        'age_max': 43,
        'flexible_spec': [
            {
                'behaviors': [
                    {
                        'id': 6002714895372,
                        'name': 'All travelers',
                    },
                ],
                'interests': [
                    {
                        'id': 6003107902433,
                        'name': 'Association football (Soccer)',
                    },
                    {
                        'id': 6003139266461,
                        'name': 'Movies',
                    },
                ],
            },
            {
                'interests': [
                    {
                        'id': 6003020834693,
                        'name': 'Music',
                    },
                ],
                'life_events': [
                    {
                        'id': 6002714398172,
                        'name': 'Newlywed (1 year)',
                    },
                ],
            },
        ],
        'exclusions': {
            'relationship_statuses': [1, 3],
            'life_events': [
                {
                    'id': 6003054185372,
                    'name': 'Recently moved',
                },
            ],
        },
    },
})
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: campaign_id,
    AdSet.Field.targeting: {
        'geo_locations': {
            'countries': ['US'],
        },
        'flexible_spec': [
            {
                'user_adclusters': [
                    {
                        'id': 6002714885172,
                        'name': 'Cooking',
                    },
                ],
            },
            {
                'user_adclusters': [
                    {
                        'id': 6006371326532,
                        'name': 'Demographic > Home > Home Owner > Recent Buyer'
                    },
                ],
            },
        ],
    },
})
ad_account_id = test_config.account_id
campaign_id = fixtures.create_campaign().get_id_assured()

# _DOC open [ADSET_CREATE_OCPM]
# _DOC vars [ad_account_id:s, campaign_id:s]
from facebookads.objects import AdSet, TargetingSpecsField

# Create an Ad Set with bid_type set to oCPM
adset = AdSet(parent_id=ad_account_id)
adset.update({
    AdSet.Field.name: 'My Ad Set for oCPM',
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.link_clicks,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.campaign_id: campaign_id,
    AdSet.Field.daily_budget: 1000,
    AdSet.Field.targeting: {
        TargetingSpecsField.geo_locations: {
            'countries': ['US'],
        },
    },
})

adset.remote_create(params={
    'status': AdSet.Status.paused,
})
# _DOC close [ADSET_CREATE_OCPM]

adset.remote_delete()
# As with any software that integrates with the Facebook platform, your use
# of this software is subject to the Facebook Developer Principles and
# Policies [http://developers.facebook.com/policy/]. This copyright notice
# shall be included in all copies or substantial portions of the software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from examples.docs import fixtures
from facebookads import test_config

ad_account_id = test_config.account_id
ad_set_id = fixtures.create_adset().get_id()

# !_DOC [pruno]
# _DOC open [ADSET_UPDATE_PACING_TYPE_STANDARD]
# _DOC vars [ad_account_id:s, ad_set_id]
from facebookads.objects import AdSet

adset = AdSet(fbid=ad_set_id, parent_id=ad_account_id)
adset.update({
    AdSet.Field.pacing_type: [AdSet.PacingType.standard],
})
adset.remote_update()
# _DOC close [ADSET_UPDATE_PACING_TYPE_STANDARD]
import time
from facebookads.objects import (
    AdSet,
    TargetingSpecsField
)

end_date = int(time.time() + 24 * 3600)

ad_set = AdSet(parent_id=ad_account_id)
ad_set.update({
    AdSet.Field.name: 'Adset Homepage Ads',
    AdSet.Field.campaign_id: campaign_id,
    AdSet.Field.daily_budget: 1000,
    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': ['US'],
        },
    },
    AdSet.Field.end_time: end_date,
})

ad_set.remote_create()
print(ad_set)
# _DOC close [ADSET_CREATE_HOMEPAGE]

ad_set.remote_delete()
# _DOC vars [ad_account_id:s, campaign_id]
from facebookads.objects import AdSet

adset = AdSet(parent_id=ad_account_id)
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: campaign_id,
    AdSet.Field.targeting: {
        'geo_locations': {
            'countries': ['US'],
        },
        'behaviors': [
            {
                'id': 6004386044572,
                'name': 'Android Owners (All)',
            },
            {
                'id': 6007101597783,
                'name': 'Business Travelers',
            },
        ],
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
# _DOC close [ADSET_CREATE_BEHAVIOR_TARGETING]
}

# _DOC open [ADSET_CREATE_TARGETING_DATE_RANGE]
# _DOC vars [ad_account_id:s, campaign_id, targeting]
import datetime
from facebookads.objects import AdSet

today = datetime.date.today()
start_time = str(today + datetime.timedelta(weeks=1))
end_time = str(today + datetime.timedelta(weeks=2))

adset = AdSet(parent_id=ad_account_id)
adset.update({
    AdSet.Field.name: 'My Ad Set',
    AdSet.Field.campaign_id: campaign_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: targeting,
    AdSet.Field.start_time: start_time,
    AdSet.Field.end_time: end_time,
})

adset.remote_create(params={
    'status': AdSet.Status.paused,
})
# _DOC close [ADSET_CREATE_TARGETING_DATE_RANGE]

adset.remote_delete()
# _DOC vars [campaign_id, ad_account_id:s, app_id, app_store_url:s]
from facebookads.objects import AdSet, TargetingSpecsField

adset = AdSet(parent_id=ad_account_id)
adset.update({
    AdSet.Field.name: 'Mobile App Installs Ad Set',
    AdSet.Field.promoted_object: {
        'application_id': app_id,
        'object_store_url': app_store_url,
    },
    AdSet.Field.campaign_id: campaign_id,
    AdSet.Field.daily_budget: 1000,
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.app_installs,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 2,
    AdSet.Field.targeting: {
        TargetingSpecsField.geo_locations: {
            'countries': ['US'],
        },
        TargetingSpecsField.page_types: [
            'mobileexternal',
            'mobilefeed',
        ],
        TargetingSpecsField.user_os: [
            'IOS',
        ],
    },
})

adset.remote_create(params={
    'status': AdSet.Status.paused,
})
ad_set.update({
    AdSet.Field.name: 'My First AdSet',
    AdSet.Field.lifetime_budget: 20000,
    AdSet.Field.start_time: start_time,
    AdSet.Field.end_time: end_time,
    AdSet.Field.campaign_id: campaign_id,
    AdSet.Field.bid_amount: 500,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.post_engagement,
    AdSet.Field.targeting: {
        TargetingSpecsField.geo_locations: {
            'countries': ['JP'],
        },
        TargetingSpecsField.genders: [1],
        TargetingSpecsField.age_min: 20,
        TargetingSpecsField.age_max: 24,
        TargetingSpecsField.interests: [
            {
                'id': 6003107902433,
                'name': 'Association football (Soccer)',
            },
        ],
        TargetingSpecsField.behaviors: [
            {
                'id': 6002714895372,
                'name': 'All travelers',
            },
        ],
        TargetingSpecsField.life_events: [
            {
                'id': 6002714398172,
                'name': 'Newlywed (1 year)',
            },
        ],
        TargetingSpecsField.home_ownership: [
            {
                'id': 6006371327132,
                'name': 'Renters',
            },
        ],
        TargetingSpecsField.page_types: [
            'desktopfeed',
            'rightcolumn',
            'mobilefeed',
            'mobileexternal',
        ],
    },
})
}).get_id_assured()

# _DOC open [ADSET_CREATE_AUDIENCE_NETWORK]
# _DOC vars [campaign_id, ad_account_id:s]
from facebookads.objects import AdSet, TargetingSpecsField

adset = AdSet(parent_id=ad_account_id)
adset.update({
    AdSet.Field.name: 'My Ad Set',
    AdSet.Field.campaign_id: campaign_id,
    AdSet.Field.daily_budget: 1000,
    AdSet.Field.billing_event: AdSet.BillingEvent.link_clicks,
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.link_clicks,
    AdSet.Field.bid_amount: 2,
    AdSet.Field.targeting: {
        TargetingSpecsField.geo_locations: {
            'countries': ['US'],
        },
        TargetingSpecsField.page_types: [
            'mobileexternal',
            'mobilefeed',
        ],
    },
})

adset.remote_create(params={
    'status': AdSet.Status.paused,
})
# _DOC close [ADSET_CREATE_AUDIENCE_NETWORK]

adset.remote_delete()
# _DOC open [ADSET_CREATE_CUSTOM_AUDIENCE_PARTNER_CATEGORIES_TARGETING]
# _DOC vars [ad_account_id:s, campaign_id, custom_audience_id, audience_name]
from facebookads.objects import AdSet

adset = AdSet(parent_id=ad_account_id)
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: campaign_id,
    AdSet.Field.targeting: {
        'geo_locations': {
            'countries': ['US'],
        },
        'custom_audiences': [
            {
                'id': custom_audience_id,
                'name': audience_name,
            },
        ],
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
# _DOC close [ADSET_CREATE_CUSTOM_AUDIENCE_PARTNER_CATEGORIES_TARGETING]

adset.remote_delete()
adset.update({
    AdSet.Field.name: 'Local awareness adset',
    AdSet.Field.daily_budget: 10000,
    AdSet.Field.campaign_id: campaign_id,
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 300,
    AdSet.Field.promoted_object: {
        'page_id': page_id,
    },
    AdSet.Field.targeting: {
        'page_types': ['mobilefeed'],
        'geo_locations': {
            'custom_locations': [
                {
                    'latitude': 37.48327,
                    'longitude': -122.15033,
                    'radius': 10,
                    'distance_unit': 'mile',
                    'address_string': '1601 Willow Road, Menlo Park, CA 94025',
                },
            ],
            'location_types': [
                'home',
                'recent',
            ],
        },
        'excluded_geo_locations': {
            'zips': [
                {
                    'key': 'US:94040',
                },
            ],
        },
    },
})
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: campaign_id,
    AdSet.Field.promoted_object: {'page_id': page_id},
    AdSet.Field.targeting: {
        TargetingSpecsField.geo_locations: {
            'countries': ['JP'],
            'regions': [
                {'key': '3886'},
            ],
            'cities': [
                {
                    'key': '2420605',
                    'radius': '10',
                    'distance_unit': 'mile',
                },
            ],
        },
        TargetingSpecsField.genders: [1],
        TargetingSpecsField.age_min: 20,
        TargetingSpecsField.age_max: 24,
        TargetingSpecsField.page_types: ['mobilefeed', 'mobileexternal'],
        TargetingSpecsField.interests: [
            {
                'id': 6003107902433,
                'name': 'Association football (Soccer)',
            },
        ],
        TargetingSpecsField.behaviors: [
            {
                'id': 6002714895372,
                'name': 'All frequent travelers',
            },
        ],
    },
})
        Campaign.Field.effective_status: Campaign.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.effective_status: AdSet.Status.paused,
        AdSet.Field.daily_budget: 3600,  # $36.00
        AdSet.Field.billing_event: 'IMPRESSIONS',  # $36.00
        AdSet.Field.is_autobid: 'true',  # $36.00
        AdSet.Field.start_time: int(time.time()) + 15,  # 15 seconds from now
        AdSet.Field.campaign_id: campaign.get_id_assured(),
        AdSet.Field.targeting: {
            TargetingSpecsField.geo_locations: {
                'countries': [
                    'US',
                ],
            },
        },
    })
    ad_set.remote_create()
    print("**** DONE: Ad Set created:")
    pp.pprint(ad_set)

    ### Upload an image to an account.
    img = AdImage(parent_id=my_account.get_id_assured())
    img[AdImage.Field.filename] = os.path.join(
        os.path.dirname(__file__),
from examples.docs import fixtures
from facebookads import test_config

ad_account_id = test_config.account_id
pixel_id = fixtures.create_ads_pixel().get_id()
campaign_id = fixtures.create_campaign().get_id_assured()

# _DOC open [ADSET_CREATE_CONVERSIONS_PURCHASE]
# _DOC vars [ad_account_id:s, campaign_id, pixel_id]
from facebookads.objects import AdSet, TargetingSpecsField

adset = AdSet(parent_id=ad_account_id)
adset.update(
    {
        AdSet.Field.name: "Ad Set oCPM",
        AdSet.Field.bid_amount: 150,
        AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
        AdSet.Field.optimization_goal: AdSet.OptimizationGoal.offsite_conversions,
        AdSet.Field.promoted_object: {"pixel_id": pixel_id, "custom_event_type": "PURCHASE"},
        AdSet.Field.daily_budget: 1000,
        AdSet.Field.campaign_id: campaign_id,
        AdSet.Field.targeting: {TargetingSpecsField.geo_locations: {"countries": ["US"]}},
    }
)

adset.remote_create(params={"status": AdSet.Status.paused})
print(adset)
# _DOC close [ADSET_CREATE_CONVERSIONS_PURCHASE]

adset.remote_delete()
Пример #29
0
    })
    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
        AdSet.Field.start_time: int(time.time()) + 15,  # 15 seconds from now
        AdSet.Field.campaign_group_id: campaign.get_id_assured(),
        AdSet.Field.targeting: {
            TargetingSpecsField.geo_locations: {
                'countries': [
                    'US',
                ],
            },
        },
    })
    ad_set.remote_create()
    print("**** DONE: Ad Set created:")
    pp.pprint(ad_set)

    ### Upload an image to an account.
    img = AdImage(parent_id=my_account.get_id_assured())
    img[AdImage.Field.filename] = os.path.join(
Пример #30
0
    })
    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
        AdSet.Field.start_time: int(time.time()) + 15,  # 15 seconds from now
        AdSet.Field.campaign_group_id: campaign.get_id_assured(),
        AdSet.Field.targeting: {
            TargetingSpecsField.geo_locations: {
                'countries': [
                    'US',
                ],
            },
        },
    })
    ad_set.remote_create()
    print("**** DONE: Ad Set created:")
    pp.pprint(ad_set)

    ### Upload an image to an account.
    img = AdImage(parent_id=my_account.get_id_assured())
    img[AdImage.Field.filename] = os.path.join(this_dir, 'test.png')
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.bid_type: AdSet.BidType.multi_premium,
    AdSet.Field.bid_info: {
        AdSet.Field.BidInfo.clicks: 20,
        AdSet.Field.BidInfo.social: 40,
        AdSet.Field.BidInfo.impressions: 40
    },
    AdSet.Field.targeting: {
        TargetingSpecsField.page_types: ['home'],
        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.remote_delete()
    Campaign.Field.objective: Campaign.Objective.conversions,
}).get_id_assured()

# !_DOC [pruno]
# _DOC open [ADSET_CREATE_CONVERSIONS]
# _DOC vars [ad_account_id:s, campaign_id, pixel_id]
from facebookads.objects import AdSet, TargetingSpecsField

adset = AdSet(parent_id=ad_account_id)
adset.update({
    AdSet.Field.name: 'Conversions Ad Set',
    AdSet.Field.promoted_object: {'pixel_id': pixel_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: {
        TargetingSpecsField.geo_locations: {
            'countries': ['US'],
        },
    },
})

adset.remote_create(params={
    'status': AdSet.Status.paused,
})
# _DOC close [ADSET_CREATE_CONVERSIONS]

adset.remote_delete()
campaign_id = fixtures.create_campaign(params=params).get_id_assured()

# _DOC open [ADSET_CREATE_CPC_PROMOTING_PAGE]
# _DOC vars [ad_account_id:s, page_id:s, campaign_id:s]
import time
from facebookads.objects import AdSet

adset = AdSet(parent_id=ad_account_id)
adset.update({
    AdSet.Field.name: 'My Ad Set',
    AdSet.Field.daily_budget: 10000,
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.page_likes,
    AdSet.Field.billing_event: AdSet.BillingEvent.page_likes,
    AdSet.Field.bid_amount: 1500,
    AdSet.Field.promoted_object: {'page_id': page_id},
    AdSet.Field.targeting: {
        'geo_locations': {
            'countries': ['US'],
        }
    },
    AdSet.Field.start_time: int(time.time()),
    AdSet.Field.campaign_id: campaign_id,
})

adset.remote_create(params={
    'status': AdSet.Status.paused,
})
print(adset)
# _DOC close [ADSET_CREATE_CPC_PROMOTING_PAGE]

adset.remote_delete()