在创建具有lead_generation优化目标的AdSet时,我应该使用什么促销对象?

时间:2016-06-15 13:16:21

标签: python facebook facebook-ads-api facebook-marketing-api

我正在使用facebookads python api,v2.6。

我正在尝试使用优化目标= lead_generation创建一个AdSet。

这是我的代码:

ad_set = AdSet(parent_id = 'act_%s' % FB_ACCOUNT)
ad_set[AdSet.Field.name]= 'Teste AdSet'
ad_set[AdSet.Field.campaign_id]='6043402838999'
ad_set[AdSet.Field.status]=AdSet.Status.paused
ad_set[AdSet.Field.billing_event] = AdSet.BillingEvent.impressions
ad_set[AdSet.Field.optimization_goal] = AdSet.OptimizationGoal.lead_generation
ad_set[AdSet.Field.daily_budget]= 100
ad_set[AdSet.Field.bid_amount]= 1
ad_set[AdSet.Field.start_time]= '2016-07-01'
ad_set[AdSet.Field.promoted_object]= 
ad_set[AdSet.Field.targeting]= {Targeting.Field.geo_locations: { 'countries': ['BR']},Targeting.Field.genders: [1],Targeting.Field.age_min: 20,Targeting.Field.age_max: 24}

ad_set.remote_create()

但是当我运行这个时,我收到了这个错误:

 Status:  400
  Response:
    {
      "error": {
        "code": 100,
        "is_transient": false,
        "error_subcode": 1885024,
        "error_user_msg": "When creating an ad set within a campaign using the Body of an error/warning message. Title is: Promoted Object Missing objective, a promoted object must be specified.",
        "error_user_title": "Promoted Object Missing",
        "message": "Invalid parameter",
        "type": "OAuthException",
        "fbtrace_id": "B9hyZlpzS7O"
      }
    }

我试图找到关于此的任何文档,但不能。在官方文档上,我没有在提升的对象选项上看到LEAD_GENERATION:

https://developers.facebook.com/docs/marketing-api/reference/ad-campaign#Creating

有人有这个问题吗?

3 个答案:

答案 0 :(得分:0)

如果有人遇到同样的问题,您必须使用page_id

答案 1 :(得分:0)

  

广告集必须将promote_object设置为相应的<PAGE_ID>

参考: https://developers.facebook.com/docs/marketing-api/guides/lead-ads/create#create

答案 2 :(得分:0)

您必须指定关联的page_id

promoted_object={"page_id": "<PAGE_ID>"}

下面的代码可能对您有帮助

from facebook_business.adobjects.adaccount import AdAccount
from facebook_business.adobjects.adset import AdSet
from facebook_business.api import FacebookAdsApi

access_token = '<ACCESS_TOKEN>'
app_secret = '<APP_SECRET>'
app_id = '<APP_ID>'
id = '<AD_ACCOUNT_ID>'
FacebookAdsApi.init(access_token=access_token)

fields = [
]
params = {
  'name': 'A CPA Ad Set',
  'campaign_id': '<adCampaignLinkClicksID>',
  'daily_budget': '5000',
  'start_time': '2019-01-09T21:31:19-0800',
  'end_time': '2019-01-16T21:31:19-0800',
  'billing_event': 'IMPRESSIONS',
  'optimization_goal': 'REACH',
  'bid_amount': '1000',
  'promoted_object': {'page_id':'<pageID>'},
  'targeting': {'geo_locations':{'countries':['US']}},
  'user_os': 'iOS',
  'publisher_platforms': 'facebook',
  'device_platforms': 'mobile',
}
print AdAccount(id).create_ad_set(
  fields=fields,
  params=params,
)