def get_adsets(adset_id):
    adset = AdSet(adset_id)
    fields = [
        AdSet.Field.name,
    ]
    adset.remote_read(fields=fields)
    return adset
Ejemplo n.º 2
0
    def copy(self):
        store_url = config['link_url'][self.param['account']][self.param['os']]
        link_url = store_url.replace('https://', 'http://')
        campaign = AdCampaign(self.param['campaign_id'])
        campaign.remote_read(
            fields=[
                AdCampaign.Field.name
            ]
        )

        adset = AdSet(self.param['adset_id'])
        adset.remote_read(
            fields=[
                AdSet.Field.name,
                AdSet.Field.daily_budget,
                AdSet.Field.pacing_type,
                AdSet.Field.promoted_object,
                AdSet.Field.targeting,
                AdSet.Field.is_autobid,
                AdSet.Field.billing_event,
                AdSet.Field.optimization_goal,
                AdSet.Field.bid_amount,
                AdSet.Field.rtb_flag
            ]
        )
        # pp.pprint(adset)

        adgroups = adset.get_ad_groups(
            fields=[
                AdGroup.Field.name,
                AdGroup.Field.creative,
                AdGroup.Field.tracking_specs,
                AdGroup.Field.status
            ],
            params={
                AdGroup.Field.status: ['ACTIVE']
            }
        )
        # pp.pprint(adgroups)

        object_store_url = adset['promoted_object']['object_store_url']
        replace_url = object_store_url.replace('https://', 'http://')
        if link_url != replace_url:
            return self.different_os_copy(campaign, adset, adgroups)
        else:
            return self.same_os_copy(campaign, adset, adgroups)
Ejemplo n.º 3
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
# 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

ad_set_id = fixtures.create_adset().get_id_assured()

# !_DOC [duliomatos]
# _DOC open [ADSET_READ_DATA_FORMAT]
# _DOC vars [ad_set_id]
from facebookads.objects import AdSet

adset = AdSet(fbid=ad_set_id)
fields = [
    AdSet.Field.start_time,
    AdSet.Field.end_time,
    AdSet.Field.configured_status,
    AdSet.Field.effective_status,
    AdSet.Field.campaign_id,
]
params = {
    'date_format': 'U',
}
adset.remote_read(fields=fields, params=params)

print(adset[AdSet.Field.effective_status])
# _DOC close [ADSET_READ_DATA_FORMAT]
def read_adset(id):
    adset = AdSet(id)
    adset.remote_read(fields=[AdSet.Field.account_id,AdSet.Field.adlabels,AdSet.Field.adset_schedule,AdSet.Field.bid_amount,AdSet.Field.bid_info,AdSet.Field.billing_event,AdSet.Field.budget_remaining,AdSet.Field.campaign,AdSet.Field.campaign_id,AdSet.Field.configured_status,AdSet.Field.created_time,AdSet.Field.creative_sequence,AdSet.Field.daily_budget,AdSet.Field.effective_status,AdSet.Field.end_time,AdSet.Field.frequency_cap,AdSet.Field.frequency_cap_reset_period,AdSet.Field.frequency_control_specs,AdSet.Field.id,AdSet.Field.is_autobid,AdSet.Field.lifetime_budget,AdSet.Field.lifetime_frequency_cap,AdSet.Field.lifetime_imps,AdSet.Field.name,AdSet.Field.optimization_goal,AdSet.Field.pacing_type,AdSet.Field.promoted_object,AdSet.Field.recommendations,AdSet.Field.rf_prediction_id,AdSet.Field.rtb_flag,AdSet.Field.start_time,AdSet.Field.status,AdSet.Field.targeting,AdSet.Field.updated_time])
    print(adset)
    return adset
# You are hereby granted a non-exclusive, worldwide, royalty-free license to
# use, copy, modify, and distribute this software in source code or binary
# form for use in connection with the web services and APIs provided by
# Facebook.

# 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

ad_set_id = fixtures.create_adset().get_id_assured()

# !_DOC [pruno]
# _DOC open [ADSET_READ_SCHEDULE]
# _DOC vars [ad_set_id]
from facebookads.objects import AdSet

adset = AdSet(fbid=ad_set_id)
adset.remote_read(fields=[AdSet.Field.adset_schedule])
# _DOC close [ADSET_READ_SCHEDULE]
Ejemplo n.º 7
0
# 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

ad_set_id = fixtures.create_adset().get_id_assured()

# !_DOC [duliomatos]
# _DOC open [ADSET_READ]
# _DOC vars [ad_set_id]
from facebookads.objects import AdSet

adset = AdSet(fbid=ad_set_id)
fields = [
    AdSet.Field.name,
    AdSet.Field.configured_status,
    AdSet.Field.effective_status,
]
adset.remote_read(fields=fields)
print(adset[AdSet.Field.name])
print(adset[AdSet.Field.configured_status])
print(adset[AdSet.Field.effective_status])
# _DOC close [ADSET_READ]
Ejemplo n.º 8
0
    def select_target(self):
        parent_id = config['act_id'][self.param['account']]
        account = AdAccount(parent_id)
        campaigns = account.get_ad_campaigns(
            fields=[
                AdCampaign.Field.name,
                AdCampaign.Field.status
            ],
            params={
                'campaign_group_status': ['ACTIVE']
            }
        )

        adset = AdSet(self.param['adset_id'])
        adset.remote_read(
            fields=[
                AdSet.Field.name,
                AdSet.Field.targeting,
                AdSet.Field.campaign_group_id,
            ]
        )
        # pp.pprint(adset)

        if(('genders' in adset['targeting']) and
                (len(adset['targeting']['genders']) == 1)):
            gender = adset['targeting']['genders'][0]
        else:
            gender = 0

        for i in range(0, len(campaigns)):
            campaign = campaigns[i]
            if adset['campaign_group_id'] == campaign['id']:
                campaign_name = campaign['name']
                break

        country_list = []
        for country in COUNTRY_CODES:
            is_checked = 0
            if (country in adset['targeting']['geo_locations']['countries']):
                is_checked = 1

            countries = {
                'name': country,
                'is_checked': is_checked
            }
            country_list.append(countries)

        custom_audiences = account.get_custom_audiences(
            fields=[
                CustomAudience.Field.name,
            ],
            params={'limit': 1000}
        )

        audience_list = []
        for i in range(0, len(custom_audiences)):
            audience = custom_audiences[i]
            is_checked = 0
            if('custom_audiences' in adset['targeting']):
                for default_audience in adset['targeting']['custom_audiences']:
                    if (audience['id'] == default_audience['id']):
                        is_checked = 1
                        break
            audiences = {
                'name': audience['name'],
                'id': audience['id'],
                'is_checked': is_checked,
            }
            audience_list.append(audiences)

        excluded_list = []
        for i in range(0, len(custom_audiences)):
            audience = custom_audiences[i]
            is_checked = 0
            if('excluded_custom_audiences' in adset['targeting']):
                excluded = adset['targeting']['excluded_custom_audiences']
                for default_excluded in excluded:
                    if (audience['id'] == default_excluded['id']):
                        is_checked = 1
                        break
            excludeds = {
                'name': audience['name'],
                'id': audience['id'],
                'is_checked': is_checked,
            }
            excluded_list.append(excludeds)

        result = {
            'account': self.param['account'],
            'adset': adset,
            'campaigns': campaigns,
            'gender': gender,
            'age_range': AGE_RANGE,
            'campaign_name': campaign_name,
            'country_list': country_list,
            'audience_list': audience_list,
            'excluded_list': excluded_list,
        }

        return result