I cannot create a simple Ad with an external link to a mobile app. I have properly set access, can create a Campaign, an AdSet, load an image, but during an Ad creation I get an error:
Ads and ad creatives must be associated with a Facebook Page. Try connecting your ad or ad creative to a Page and resubmit your ad.
But I have associated a page! Here is my code:
# No problem with these ones
adset = ...
image_hash = '...'
url = 'https://itunes.apple.com/app/96...'
page_id = '25036...'
# Create an Ad Creative
creative = AdCreative()
creative['_parent_id'] = my_ads_acc_id
creative[AdCreative.Field.title] = 'Aivan Test Creative'
creative[AdCreative.Field.body] = 'Aivan Test Ad Creative Body'
creative[AdCreative.Field.actor_id] = page_id
creative[AdCreative.Field.link_url] = url
creative[AdCreative.Field.object_url] = url
creative[AdCreative.Field.object_type] = AdCreative.ObjectType.domain
creative[AdCreative.Field.call_to_action_type] = AdCreative.CallToActionType.use_mobile_app
creative[AdCreative.Field.image_hash] = image_hash
# Create an Ad
ad = Ad()
ad['_parent_id'] = my_ads_acc_id
ad[Ad.Field.name] = 'Aivan Ad'
ad[Ad.Field.adset_id] = adset[AdSet.Field.id]
ad[Ad.Field.creative] = creative
# This line generates an exception:
ad.remote_create(params={
'status': Ad.Status.paused,
})
I have specified the actor_id
field, also I have tried other different code samples, but nothing works well. How can I connect a page?
Additional info:
-
My app is in development mode. I cannot turn the production mode because it needs a review which needs a completed app.
-
I have tried to use
object_story_spec
withlink_data
in it, but it creates other error because it doesn’t work in development mode. -
The app and the page are linked with Facebook Business Manager.
-
The results is the same if I init the API with app token or system user token:
FacebookAdsApi.init(app_id, app_secret, app_access_token / system_user_token)
. The system user has access to both Ads Account and the Page.
2
Answers
I've solved the problem a long time ago, and since that time my server app successfully created lots of Facebook ads of both types, for websites and mobile apps. The first step to solve the problem was to understand that these ads types are completely different on Facebook, they need different settings for Campaign, AdSet & Ad. Here is my code for mobile ads creation.
1) Create Campaign object.
account_id
must be the ID of your Ad Account.2) Create AdSet object.
Note that to create mobile ad, you initially need to register your mobile app as a Facebook app (here you will get
ad_app_id
) and specify links to Apple App Store and Google Play Market. So, the value ofapp_store_url
must be equal to one of those links in your Facebook app settings. Unfortunately, app can be registered only manually (if you know how to do it programmatically – write a comment, please).Also note that
billing_event
andoptimization_goal
are connected with ads type (mobile/web) and with each other, you cannot just choose another one. (But if you know that this is possible, or there are some docs on this topics – let me know.)budget
is a money amount in the currency of your Ad Account. You can specify eitherlifetime_budget
or something like day_budget, read the docs about it.3) Then, you have to create AdCreative object with some other sub objects. Note that some of these lines of code are necessary for FB ad only, others for IG, others for both of them, but together they work well for everything. You can find description for all the formats here.
To upload an image and get
image_hash
, check out this doc. Thepage_id
must be an ID of the page which name and logo will be shown as the author of the ad.You must note that the user, who creates the ad, must have an access to this page, to the mobile app registered on FB (
ad_app_id
), and to the Ad Account (account_id
). In my server application I use Facebook system users for all the work with API.4) And finally, create the Ad object itself:
That's all!
Maybe someone will need to use or just want to see the difference when creating FB/IG ads for websites, it is a little bit simpler. So, here is my code for website ads creation.
1) Create Campaign object. Notice that website ads has a different
objective
.account_id
must be the ID of your Ad Account.2) Create AdSet object. Note that
billing_event
andoptimization_goal
are connected with ads type (mobile/web) and with each other. Also, here you don’t need to specifypromoted_object
in the AdSet.Rules for budget are the same:
budget
is a money amount in the currency of your Ad Account. You can specify eitherlifetime_budget
or something like day_budget, read the docs about it.3) Then, you have to create AdCreative object with some other sub objects. You can find description for all the formats here.
To upload an image and get
image_hash
, check out this doc. Thepage_id
must be an ID of the page which name and logo will be shown as the author of the ad. Note that the user, who creates the ad, must have an access to this page, to the mobile app registered on FB (ad_app_id
), and to the Ad Account (account_id
).4) And finally, create the Ad object itself:
As you can see, to promote websites you don’t need to register them on Facebook (in contrast to mobile ads).