本文整理汇总了Python中facebookads.objects.AdAccount.get_custom_audiences方法的典型用法代码示例。如果您正苦于以下问题:Python AdAccount.get_custom_audiences方法的具体用法?Python AdAccount.get_custom_audiences怎么用?Python AdAccount.get_custom_audiences使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类facebookads.objects.AdAccount
的用法示例。
在下文中一共展示了AdAccount.get_custom_audiences方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getCustomAudiences
# 需要导入模块: from facebookads.objects import AdAccount [as 别名]
# 或者: from facebookads.objects.AdAccount import get_custom_audiences [as 别名]
def getCustomAudiences(my_account):
ad_account = AdAccount("{AD_ACCOUNT_ID}".format(AD_ACCOUNT_ID = my_account['id']))
custom_audiences = ad_account.get_custom_audiences(fields=[CustomAudience.Field.name])
# audiences = my_account.get_custom_audiences(fields=[
# CustomAudience.Field.name,
# CustomAudience.Field.description])
return custom_audiences
示例2: AdAccount
# 需要导入模块: from facebookads.objects import AdAccount [as 别名]
# 或者: from facebookads.objects.AdAccount import get_custom_audiences [as 别名]
# _DOC open [ADACCOUNT_GET_ADIMAGES]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount
account = AdAccount(ad_account_id)
images = account.get_ad_images()
# _DOC close [ADACCOUNT_GET_ADIMAGES]
# _DOC open [ADACCOUNT_GET_CUSTOMAUDIENCES_NAME]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount, CustomAudience
ad_account = AdAccount(ad_account_id)
custom_audiences = ad_account.get_custom_audiences(fields=[
CustomAudience.Field.name
])
for custom_audience in custom_audiences:
print(custom_audience[CustomAudience.Field.name])
# _DOC close [ADACCOUNT_GET_CUSTOMAUDIENCES_NAME]
# _DOC open [ADACCOUNT_GET_INSIGHTS_VIDEO_VIEWS]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount, Insights
account = AdAccount(ad_account_id)
params = {
'action_breakdowns': Insights.ActionBreakdown.action_video_type,
'date_preset': Insights.Preset.last_30_days,
示例3: AdAccount
# 需要导入模块: from facebookads.objects import AdAccount [as 别名]
# 或者: from facebookads.objects.AdAccount import get_custom_audiences [as 别名]
# 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 facebookads import test_config
ad_account_id = test_config.account_id
# _DOC oncall [pruno]
# _DOC open [ADACCOUNT_GET_CUSTOMAUDIENCES_DATA_SOURCE_SUBTYPE]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount, CustomAudience
ad_account = AdAccount(ad_account_id)
custom_audiences = ad_account.get_custom_audiences(fields=[
CustomAudience.Field.data_source,
CustomAudience.Field.subtype,
])
# _DOC close [ADACCOUNT_GET_CUSTOMAUDIENCES_DATA_SOURCE_SUBTYPE]
开发者ID:dud3,项目名称:facebook-python-ads-sdk,代码行数:32,代码来源:ADACCOUNT_GET_CUSTOMAUDIENCES_DATA_SOURCE_SUBTYPE.py
示例4: same_os_copy
# 需要导入模块: from facebookads.objects import AdAccount [as 别名]
# 或者: from facebookads.objects.AdAccount import get_custom_audiences [as 别名]
def same_os_copy(self, campaign, adset, adgroups):
parent_id = config['act_id'][self.param['account']]
account = AdAccount(parent_id)
custom_audiences = account.get_custom_audiences(
fields=[
CustomAudience.Field.name,
],
params={'limit': 100}
)
copy_custom_audience = []
copy_excluded_custom_audience = []
excluded_ids = self.param.getlist('excluded_custom_audiences')
for i in range(0, len(custom_audiences)):
custom_audience = custom_audiences[i]
if custom_audience['id'] in self.param.getlist('custom_audiences'):
audience = {
'id': custom_audience['id'],
'name': custom_audience['name']
}
copy_custom_audience.append(audience)
if custom_audience['id'] in excluded_ids:
excluded_audience = {
'id': custom_audience['id'],
'name': custom_audience['name']
}
copy_excluded_custom_audience.append(excluded_audience)
copy_targeting = copy.deepcopy(adset['targeting'])
copy_targeting['age_max'] = self.param['age_max']
copy_targeting['age_min'] = self.param['age_min']
copy_targeting['geo_locations']['countries'] = self.param.getlist('countries')
copy_targeting['custom_audiences'] = copy_custom_audience
copy_targeting['excluded_custom_audiences'] = copy_excluded_custom_audience
# Defaults to all. Do not specify 0.
if(self.param['gender']):
copy_targeting['genders'] = [self.param['gender']]
else:
copy_targeting['genders'] = [1, 2]
copy_adset = AdSet(parent_id=parent_id)
copy_adset.update({
AdSet.Field.name: self.param['adset_name'],
AdSet.Field.daily_budget: adset['daily_budget'],
AdSet.Field.promoted_object: adset['promoted_object'],
AdSet.Field.is_autobid: adset['is_autobid'],
AdSet.Field.targeting: copy_targeting,
AdSet.Field.status: self.param['status'],
AdSet.Field.campaign_group_id: self.param['campaign_id'],
AdSet.Field.billing_event: adset['billing_event'],
AdSet.Field.optimization_goal: adset['optimization_goal'],
AdSet.Field.rtb_flag: adset['rtb_flag']
})
if 'bid_amount' in adset:
copy_adset.update({
AdSet.Field.bid_amount: adset['bid_amount']
})
copy_adset.remote_create()
print("*** DONE: Copy AdSet ***")
pp.pprint(copy_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']
}
)
for i in range(0, len(adgroups)):
adgroup = adgroups[i]
copy_adgroup = AdGroup(parent_id=parent_id)
copy_adgroup.update({
AdGroup.Field.name: adgroup['name'],
AdGroup.Field.campaign_id: copy_adset['id'],
AdGroup.Field.status: adgroup['adgroup_status'],
AdGroup.Field.creative: {
AdGroup.Field.Creative.creative_id: adgroup['creative']['id']
},
AdGroup.Field.tracking_specs: adgroup['tracking_specs']
})
copy_adgroup.remote_create()
print("*** DONE: Copy AdGroup ***")
pp.pprint(copy_adgroup)
result = {
'adset': copy_adset,
'campaign': campaign,
'adgroups': adgroups
}
return result
示例5: different_os_copy
# 需要导入模块: from facebookads.objects import AdAccount [as 别名]
# 或者: from facebookads.objects.AdAccount import get_custom_audiences [as 别名]
def different_os_copy(self, campaign, adset, adgroups):
parent_id = config['act_id'][self.param['account']]
link_url = config['link_url'][self.param['account']][self.param['os']]
account = AdAccount(parent_id)
custom_audiences = account.get_custom_audiences(
fields=[
CustomAudience.Field.name,
],
params={'limit': 100}
)
copy_custom_audience = []
copy_excluded_audience = []
for i in range(0, len(custom_audiences)):
custom_audience = custom_audiences[i]
if custom_audience['id'] in self.param.getlist('custom_audiences'):
audience = {
'id': custom_audience['id'],
'name': custom_audience['name']
}
copy_custom_audience.append(audience)
if custom_audience['id'] in self.param.getlist('excluded_custom_audiences'):
excluded_audience = {
'id': custom_audience['id'],
'name': custom_audience['name']
}
copy_excluded_audience.append(excluded_audience)
copy_promoted_object = copy.deepcopy(adset['promoted_object'])
copy_promoted_object['object_store_url'] = link_url
copy_targeting = copy.deepcopy(adset['targeting'])
copy_targeting['user_os'] = [config['user_os'][self.param['os']]]
copy_targeting['age_max'] = self.param['age_max']
copy_targeting['age_min'] = self.param['age_min']
copy_targeting['geo_locations']['countries'] = self.param.getlist('countries')
copy_targeting['custom_audiences'] = copy_custom_audience
copy_targeting['excluded_custom_audiences'] = copy_excluded_audience
# Default to all.
if 'user_device' in copy_targeting:
del copy_targeting['user_device']
# Defaults to all. Do not specify 0.
if(self.param['gender']):
copy_targeting['genders'] = [self.param['gender']]
else:
copy_targeting['genders'] = [1, 2]
copy_adset = AdSet(parent_id=parent_id)
copy_adset.update({
AdSet.Field.name: self.param['adset_name'],
AdSet.Field.daily_budget: adset['daily_budget'],
AdSet.Field.promoted_object: copy_promoted_object,
AdSet.Field.is_autobid: adset['is_autobid'],
AdSet.Field.targeting: copy_targeting,
AdSet.Field.status: self.param['status'],
AdSet.Field.campaign_group_id: self.param['campaign_id'],
AdSet.Field.billing_event: adset['billing_event'],
AdSet.Field.optimization_goal: adset['optimization_goal'],
AdSet.Field.rtb_flag: adset['rtb_flag']
})
if 'bid_amount' in adset:
copy_adset.update({
AdSet.Field.bid_amount: adset['bid_amount']
})
copy_adset.remote_create()
print("*** DONE: Copy AdSet ***")
pp.pprint(copy_adset)
creatives = adset.get_ad_creatives(
fields=[
AdCreative.Field.name,
AdCreative.Field.object_story_spec
],
params={
'limit': 50
}
)
for i in range(0, len(adgroups)):
adgroup = adgroups[i]
creative = {}
for j in range(0, len(creatives)):
if (adgroup['creative']['id'] == creatives[j]['id']):
creative = creatives[j]
break
object_story_spec = creative['object_story_spec']
if 'link_data' in object_story_spec:
copy_object_story_spec = self.get_object_story_spec_for_image(
object_story_spec,
link_url
)
elif 'video_data' in object_story_spec:
copy_object_story_spec = self.get_object_story_spec_for_video(
object_story_spec,
#.........这里部分代码省略.........
示例6: select_target
# 需要导入模块: from facebookads.objects import AdAccount [as 别名]
# 或者: from facebookads.objects.AdAccount import get_custom_audiences [as 别名]
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