I am trying to create a custom audience for a Facebook campaign using a video engagement. I have used the Create_Ad_Video function to create an adVideo and have uploaded it successfully. However, when I use the Create_Video_Custom_Audience function to create a custom audience for the uploaded video
import facebook_business as fb
from facebook_business.api import FacebookAdsApi
from facebook_business.adobjects.adaccount import AdAccount
from facebook_business.adobjects.campaign import Campaign
from facebook_business.adobjects.adset import AdSet
from facebook_business.adobjects.ad import Ad
from facebook_business.adobjects.targetingsearch import TargetingSearch
from facebook_business.adobjects.targeting import Targeting
from facebook_business.adobjects.adcreative import AdCreative
from facebook_business.adobjects.adimage import AdImage
from facebook_business.adobjects.advideo import AdVideo
from facebook_business.adobjects.page import Page
from facebook_business.adobjects.customaudience import CustomAudience
FacebookAdsApi.init(app_id=my_app_id, app_secret=my_app_secret, access_token=my_access_token)
ad_account_id = 'act_XXXXXX'
my_account = AdAccount(ad_account_id)
More detailed, I am using this function to create an adVideo:
def Create_Ad_Video (
creative_media=None,
creative_media_name=None,
):
_result = []
filename, extension = os.path.splitext(creative_media)
response = requests.get(creative_media)
name = str(uuid.uuid4())
filename = name + extension
full_path = './data/' + filename
with open(full_path, 'wb') as f:
f.write(response.content)
fields = [
AdVideo.Field.id,
AdVideo.Field.name,
AdVideo.Field.status,
AdVideo.Field.created_time,
AdVideo.Field.updated_time,
]
params = {
AdVideo.Field.filename: full_path,
AdVideo.Field.name: creative_media_name
}
video = my_account.create_ad_video(fields=fields, params=params)
_result.append({'id': video[AdVideo.Field.id]})
return _result
And the following function to create a custom audience for the video I have already uploaded
def Create_Video_Custom_Audience (
audience_name=None,
audience_description=None,
audience_retention_days=None,
audience_retention_seconds=None,
video_id=None,
pixel_id=pixel_id,
):
_result = []
fields = []
params = {
'name': audience_name,
'rule': {'inclusions':{'operator':'or','rules':[{'event_sources':[{'id':video_id,'type':'video'}],'retention_seconds':31536000,'filter':{'operator':'and','filters':[{'field':'event','operator':'eq','value':'page_engaged'}]}}]}},
'prefill': '1',
}
# OR
params = {
'name': audience_name,
'subtype': CustomAudience.Subtype.engagement,
'description': audience_description,
'rule': [{"event_name":"video_view_10s","object_id":video_id}],
'data_source': {
'type': CustomAudience.EnumSourceType.event_based,
'sub_type': CustomAudience.EnumSubtype.event_based.engagement_events,
'creation_params': {'prefill': 'true'},
},
'audience_retention_days': 365,
}
# OR
params = {
'name': audience_name,
'subtype': 'ENGAGEMENT',
'description': audience_description,
'retention_days': 365,
'rule': [{"event_name":"video_view_10s","object_id": video_id}],
'data_source': {
'type': 'EVENT_BASED',
'subtype': 'ENGAGEMENT_EVENTS',
'creation_params': {'prefill': 'true'}
}
}
_result = my_account.create_custom_audience(
fields=fields,
params=params,
)
return _result
Then I receive the following error message:
Status: 400
Response:
{
"error": {
"message": "(#2654) No Page or New Page Experience Association: You can't create a video engagement Custom Audience with video VideoID because this video isn't associated with a Page or New Page Experience.",
"type": "OAuthException",
"code": 2654,
"error_subcode": 1713216,
"fbtrace_id": "XXXXXXXX"
}
}
The problem is that when i am creating the same custom audience using the UI through https://business.facebook.com/adsmanager/audiences i do not associate the video to any Page or New Page Experience.
the result I want to achieve is the following:
<CustomAudience> {
"account_id": "<Account_ID>",
"data_source": {
"creation_params": "{\"prefill\":\"true\"}",
"sub_type": "ENGAGEMENT_EVENTS",
"type": "EVENT_BASED"
},
"delivery_status": {
"code": 200,
"description": "This audience is ready for use."
},
"description": "",
"id": "<ID>",
"is_value_based": false,
"name": "TEST VIDEO AUDIENCE",
"operation_status": {
"code": 441,
"description": "We're finding people who fit your audience criteria. You can start running ads with this audience straight away, but be aware that your audience size will increase as the audience is populated."
},
"retention_days": 365,
"rule": "[{\"event_name\":\"video_view_10s\",\"object_id\":<OJECT_ID>}]",
"subtype": "ENGAGEMENT"
}
Can someone point out the problem and how to solve it ??
Thanks in advance