Ejemplo n.º 1
0
    def create_creative(self, accountid, name, imagehash, message, appinfo):
        """
        Step 4: create ad creative with call to action type to be
        'USE_MOBILE_APP'. See
        [Ad Creative](https://developers.facebook.com/docs/marketing-api/adcreative)
        for further details on the API used here.
        """
        link_data = LinkData()
        link_data[LinkData.Field.name] = appinfo['app_name']
        link_data[LinkData.Field.link] = appinfo['appstore_link']
        link_data[LinkData.Field.message] = message
        link_data[LinkData.Field.image_hash] = imagehash
        call_to_action = {'type': 'USE_MOBILE_APP'}
        call_to_action['value'] = {
            'link': appinfo['appstore_link'],
            'app_link': appinfo['app_deep_link'],
            'application': appinfo['fbapplication_id']
        }
        link_data[LinkData.Field.call_to_action] = call_to_action

        object_story_spec = ObjectStorySpec()
        object_story_spec[ObjectStorySpec.Field.page_id] = appinfo['fbpage_id']
        object_story_spec[ObjectStorySpec.Field.link_data] = link_data

        creative = AdCreative(parent_id=accountid)
        creative[AdCreative.Field.name] = name
        creative[AdCreative.Field.object_story_spec] = object_story_spec
        creative.remote_create()

        return creative[AdCreative.Field.id]
Ejemplo n.º 2
0
    def create_creative(self, account_id, name, image_hash, message, page_id,
                        app_name, app_store_link, deferred_app_link):
        """
        Step 4: create ad creative with call to action type to be
        'INSTALL_MOBILE_APP'. See [Ad Creative][1] for further details on the
        API used here.
        [1]: https://developers.facebook.com/docs/marketing-api/adcreative
        """
        link_data = LinkData()
        link_data[LinkData.Field.name] = app_name
        link_data[LinkData.Field.link] = app_store_link
        link_data[LinkData.Field.message] = message
        link_data[LinkData.Field.image_hash] = image_hash
        call_to_action = {'type': 'INSTALL_MOBILE_APP'}
        call_to_action['value'] = {'link': app_store_link}
        if deferred_app_link:
            call_to_action['value']['app_link'] = deferred_app_link

        link_data[LinkData.Field.call_to_action] = call_to_action

        object_story_spec = ObjectStorySpec()
        object_story_spec[ObjectStorySpec.Field.page_id] = page_id
        object_story_spec[ObjectStorySpec.Field.link_data] = link_data

        creative = AdCreative(parent_id=account_id)
        creative[AdCreative.Field.name] = name
        creative[AdCreative.Field.object_story_spec] = object_story_spec
        creative.remote_create()

        return creative[AdCreative.Field.id]
Ejemplo n.º 3
0
def create_creative(message, link, image_hash):
    link_data = AdCreativeLinkData()
    link_data[AdCreativeLinkData.Field.message] = message
    link_data[AdCreativeLinkData.Field.link] = link
    link_data[AdCreativeLinkData.Field.image_hash] = image_hash

    object_story_spec = AdCreativeObjectStorySpec()
    object_story_spec[
        AdCreativeObjectStorySpec.Field.page_id] = '102142938001931'
    object_story_spec[AdCreativeObjectStorySpec.Field.link_data] = link_data

    creative = AdCreative(parent_id='act_171349487548919')
    creative[AdCreative.Field.name] = 'AdCreative for Link Ad'
    creative[AdCreative.Field.object_story_spec] = object_story_spec
    creative.remote_create()
    return creative
Ejemplo n.º 4
0
def create_adcreative(_img=None, _name=None, _message=None, _link='https://relaygo.com/relay', _link_title=None, _link_desc=None, _keyvalue=None, _page_id = page_id, _instagram_id = instagram_id, _ad_account=ad_account_id):
    from facebook_business.adobjects.adimage import AdImage
    from facebook_business.adobjects.adcreative import AdCreative
    from facebook_business.adobjects.adcreativelinkdata import AdCreativeLinkData
    from facebook_business.adobjects.adcreativeobjectstoryspec import AdCreativeObjectStorySpec
    if _img is None:
        _img = '/Users/smalone/Desktop/Images/RelayAd_1a.png'
    if _name is None:
        _name = 'API Test AdCreative Name - DELETE'
    if _message is None:
        _message = 'Programmatic API Message'
    if _link_title is None:
        _link_title = "Relay is really awesome"
    if _link_desc is None:
        _link_desc = 'You should buy it'
    image = AdImage(parent_id=_ad_account)
    image[AdImage.Field.filename] = _img
    image.remote_create()
    image_hash = image[AdImage.Field.hash]

    link_data = AdCreativeLinkData()
    link_data[AdCreativeLinkData.Field.message] = _message
    link_data[AdCreativeLinkData.Field.link] = _link
    link_data[AdCreativeLinkData.Field.image_hash] = image_hash
    # link_data[AdCreativeLinkData.Field.format_option] = 'single_image' #carousel_images_multi_items, carousel_images_single_item, carousel_slideshows
    link_data[AdCreativeLinkData.Field.name] = _link_title
    link_data[AdCreativeLinkData.Field.caption] = 'relaygo.com'
    link_data[AdCreativeLinkData.Field.description] = _link_desc
    link_data[AdCreativeLinkData.Field.call_to_action] = {"type":"LEARN_MORE",
                                                          "value": {"link":_link,}}

    object_story_spec = AdCreativeObjectStorySpec()
    object_story_spec[AdCreativeObjectStorySpec.Field.page_id] = _page_id
    object_story_spec[AdCreativeObjectStorySpec.Field.instagram_actor_id] = _instagram_id
    object_story_spec[AdCreativeObjectStorySpec.Field.link_data] = link_data

    creative = AdCreative(parent_id=_ad_account)
    creative[AdCreative.Field.name] = _name
    creative[AdCreative.Field.object_story_spec] = object_story_spec
    if _keyvalue != None:
        creative[AdCreative.Field.url_tags] = _keyvalue
    creative.remote_create()

    return creative
Ejemplo n.º 5
0
    def s4_create_creative(self, accountid, name, imagehashes, linktitles,
                           deeplinks, message, appinfo):
        """
        Step 4: create ad creative with call to action type to be
        'INSTALL_MOBILE_APP'. See
        [Ad Creative](
        https://developers.facebook.com/docs/marketing-api/adcreative)
        for further details on the API used here.
        """
        attachments = []
        for index, imagehash in enumerate(imagehashes):
            attachment = AttachmentData()
            attachment[AttachmentData.Field.name] = linktitles[index]
            attachment[AttachmentData.Field.link] = appinfo['appstore_link']
            attachment[AttachmentData.Field.image_hash] = imagehash
            call_to_action = {
                'type': 'INSTALL_MOBILE_APP',
            }
            if deeplinks and index in deeplinks:
                call_to_action['value']['app_link'] = deeplinks[index]

            attachment[AttachmentData.Field.call_to_action] = call_to_action
            attachments.append(attachment)

        link_data = LinkData()
        link_data[LinkData.Field.link] = appinfo['appstore_link']
        link_data[LinkData.Field.message] = message
        link_data[LinkData.Field.child_attachments] = attachments

        object_story_spec = ObjectStorySpec()
        object_story_spec[ObjectStorySpec.Field.page_id] = appinfo['fbpage_id']
        object_story_spec[ObjectStorySpec.Field.link_data] = link_data

        creative = AdCreative(parent_id=accountid)
        creative[AdCreative.Field.name] = name
        creative[AdCreative.Field.object_story_spec] = object_story_spec
        creative.remote_create()

        return creative[AdCreative.Field.id]
Ejemplo n.º 6
0
def create_video_creation(video_id, image_url, page_id):
    FacebookAdsApi.init(access_token=my_access_token)

    video_data = AdCreativeVideoData()
    # video_data[AdCreativeVideoData.Field.description] = 'Hi World'
    video_data[AdCreativeVideoData.Field.video_id] = video_id
    video_data[AdCreativeVideoData.Field.image_url] = image_url
    video_data[AdCreativeVideoData.Field.call_to_action] = {
        'type': 'LIKE_PAGE',
        'value': {
            'page': page_id,
        },
    }

    object_story_spec = AdCreativeObjectStorySpec()
    object_story_spec[AdCreativeObjectStorySpec.Field.page_id] = page_id
    object_story_spec[AdCreativeObjectStorySpec.Field.video_data] = video_data

    creative = AdCreative(parent_id=f'act_{ad_account}')
    creative[AdCreative.Field.name] = 'Video Ad Creative-0'
    creative[AdCreative.Field.object_story_spec] = object_story_spec
    return creative.remote_create()
def create_video_creation(video_id, destination_url, description, adgroup,
                          page_id):
    FacebookAdsApi.init(access_token=my_access_token)
    video_data = AdCreativeVideoData()
    # video_data[AdCreativeVideoData.Field.description] = description
    video_data[AdCreativeVideoData.Field.video_id] = video_id
    image_hash = image_upload(adgroup)
    video_data[AdCreativeVideoData.Field.image_hash] = image_hash
    video_data[AdCreativeVideoData.Field.call_to_action] = {
        'type': 'LIKE_PAGE',
        'value': {
            'page': page_id,
        },
    }

    object_story_spec = AdCreativeObjectStorySpec()
    object_story_spec[AdCreativeObjectStorySpec.Field.page_id] = page_id
    object_story_spec[AdCreativeObjectStorySpec.Field.video_data] = video_data

    creative = AdCreative(parent_id=f'act_{ad_account}')
    creative[AdCreative.Field.name] = f'Video {adgroup}'
    creative[AdCreative.Field.object_story_spec] = object_story_spec
    creative[AdCreative.Field.url_tags] = destination_url
    return creative.remote_create()['id']
Ejemplo n.º 8
0
            AdSet.OptimizationGoal.link_clicks
        adset[AdSet.Field.daily_budget] = 1000
        adset[AdSet.Field.campaign_id] = campaign[Campaign.Field.id]
        adset[AdSet.Field.targeting] = {
            Targeting.Field.geo_locations: {
                Targeting.Field.countries: ['NO'],
            },
        }
        # adset[AdSet.Field.promoted_object] = {
        #     'product_set_id': '490354758419836',
        # }

        adset.remote_create()

        story = AdCreativeObjectStorySpec()
        story[story.Field.page_id] = 240295992766537
        story[story.Field.template_data] = {
            'message': 'Test {{product.name | titleize}}',
            'link': 'http://instebo.one',
            'name': 'Headline {{product.price}}',
            'description': 'Description {{product.description}}',
        }

        creative = AdCreative(parent_id=act_cid)
        creative[AdCreative.Field.name] = 'Dynamic Ad Template Creative Sample'
        creative[AdCreative.Field.object_story_spec] = story
        creative[AdCreative.Field.product_set_id] = 490354758419836
        creative.remote_create()

    else:
        print("no api found")
Ejemplo n.º 9
0
    def create_lead_ad(
        self,
        account_id,
        name,
        page_id,
        form_id,
        optimization_goal,
        billing_event,
        bid_amount,
        daily_budget,
        targeting,
        image_path,
        message,
        link,
        caption,
        description,
        cta_type='SIGN_UP',
    ):
        """
        Create Campaign
        """
        campaign = Campaign(parent_id=account_id)
        campaign[Campaign.Field.name] = name + ' Campaign'
        campaign[Campaign.Field.objective] = \
            Campaign.Objective.lead_generation

        campaign.remote_create(params={
            'status': Campaign.Status.paused
        })

        """
        Create AdSet
        """
        adset = AdSet(parent_id=account_id)
        adset[AdSet.Field.campaign_id] = campaign.get_id_assured()
        adset[AdSet.Field.name] = name + ' AdSet'
        adset[AdSet.Field.promoted_object] = {
            'page_id': page_id,
        }
        adset[AdSet.Field.optimization_goal] = optimization_goal
        adset[AdSet.Field.billing_event] = billing_event
        adset[AdSet.Field.bid_amount] = bid_amount
        adset[AdSet.Field.daily_budget] = daily_budget
        adset[AdSet.Field.targeting] = targeting
        adset.remote_create()

        """
        Image
        """
        image = AdImage(parent_id=account_id)
        image[AdImage.Field.filename] = image_path
        image.remote_create()
        image_hash = image[AdImage.Field.hash]

        """
        Create Creative
        """
        link_data = LinkData()
        link_data[LinkData.Field.message] = message
        link_data[LinkData.Field.link] = link
        link_data[LinkData.Field.image_hash] = image_hash
        link_data[LinkData.Field.caption] = caption
        link_data[LinkData.Field.description] = description
        link_data[LinkData.Field.call_to_action] = {
            'type': cta_type,
            'value': {
                'lead_gen_form_id': form_id,
            },
        }

        object_story_spec = ObjectStorySpec()
        object_story_spec[ObjectStorySpec.Field.page_id] = page_id
        object_story_spec[ObjectStorySpec.Field.link_data] = link_data

        creative = AdCreative(parent_id=account_id)
        creative[AdCreative.Field.name] = name + ' Creative'
        creative[AdCreative.Field.object_story_spec] = object_story_spec
        creative.remote_create()

        """
        Create Ad
        """
        ad = Ad(parent_id=account_id)
        ad[Ad.Field.name] = name
        ad[Ad.Field.adset_id] = adset.get_id_assured()
        ad[Ad.Field.creative] = {'creative_id': str(creative.get_id_assured())}
        ad.remote_create()

        return {
            'image_hash': image_hash,
            'campaign_id': campaign['id'],
            'adset_id': adset['id'],
            'creative_id': creative['id'],
            'ad_id': ad['id'],
        }