from facebookads.specs import TemplateData, ObjectStorySpec

template = TemplateData()
template.update({
    TemplateData.Field.name: '{{page.name}}',
    TemplateData.Field.message: 'Ad Message',
    TemplateData.Field.description: 'Ad Description',
    TemplateData.Field.link: url,
    TemplateData.Field.picture: image_url,
    TemplateData.Field.call_to_action: {
        'type': 'CALL_NOW',
    },
})

story = ObjectStorySpec()
story.update({
    ObjectStorySpec.Field.page_id: page_id,
    ObjectStorySpec.Field.template_data: template,
})

creative = AdCreative(parent_id=ad_account_id)
creative.update({
    AdCreative.Field.place_page_set_id: ad_place_page_set_id,
    AdCreative.Field.dynamic_ad_voice: 'DYNAMIC',
    AdCreative.Field.object_story_spec: story,
})
creative.remote_create()
# _DOC close [ADCREATIVE_CREATE_DLA_DYNAMIC_CALL_NOW]

creative.remote_delete()
    LinkData.Field.message: "Message",
    LinkData.Field.name: "Name",
    LinkData.Field.caption: "Caption",
    LinkData.Field.description: "My description",
    LinkData.Field.call_to_action: {
        "type": "USE_APP",
        "value": {
            "link": url,
            "link_caption": "CTA caption",
        },
    },
})

story = ObjectStorySpec()
story.update({
    ObjectStorySpec.Field.link_data: link_data,
    ObjectStorySpec.Field.page_id: page_id,
})

creative = AdCreative()
creative.update({
    AdCreative.Field.object_story_spec: story,
})

account = AdAccount(ad_account_id)
params = {
    AdPreview.Field.ad_format: AdPreview.AdFormat.desktop_feed_standard,
    AdPreview.Field.creative: creative.export_data(),
}
ad_preview = account.get_ad_preview(params=params)
print(ad_preview)
# _DOC close [ADACCOUNT_GET_PREVIEWS_MAIA_WITH_OBJECT_STORY_SPEC]
# _DOC vars [video_id, thumbnail_url:s, app_store_url:s, page_id, ad_account_id:s]
from facebookads.objects import AdCreative
from facebookads.specs import ObjectStorySpec, VideoData

video_data = VideoData()
video_data.update({
    VideoData.Field.video_id: video_id,
    VideoData.Field.description: 'Creative description',
    VideoData.Field.image_url: thumbnail_url,
    VideoData.Field.call_to_action: {
        'type': 'INSTALL_MOBILE_APP',
        'value': {
            'link': app_store_url,
            'link_title': 'Link title',
        },
    },
})

story = ObjectStorySpec()
story.update({
    ObjectStorySpec.Field.page_id: page_id,
    ObjectStorySpec.Field.video_data: video_data,
})

creative = AdCreative(parent_id=ad_account_id)
creative[AdCreative.Field.object_story_spec] = story
creative.remote_create()
# _DOC close [ADCREATIVE_CREATE_MAIA_VIDEO]

creative.remote_delete()