def new(request): """ Returns a new line item """ client = Client(settings.SOCIAL_AUTH_TWITTER_KEY, settings.SOCIAL_AUTH_TWITTER_SECRET, settings.TWITTER_ACCESS_TOKEN, settings.TWITTER_ACCESS_TOKEN_SECRET) account_id = request.GET.get("account_id", "") campaign_id = request.GET.get("campaign_id", "") campaign_name = request.GET.get("name", "") budget = request.GET.get("budget", "") account_id = request.GET.get("account_id", "") name = request.GET.get("name", "") bid_amount = request.GET.get("bid_amount", "") json_data = {} try: account = client.accounts(account_id) # create your campaign line_item = LineItem(account) line_item.campaign_id = campaign_id line_item.name = name line_item.product_type = PRODUCT.PROMOTED_TWEETS line_item.placements = [PLACEMENT.ALL_ON_TWITTER] line_item.objective = OBJECTIVE.TWEET_ENGAGEMENTS line_item.bid_amount_local_micro = int(bid_amount) * 1000 line_item.paused = True line_item.save() json_data = { "account_id": account_id, "campaign_name": campaign_name, "campaign_id": campaign_id } except Error as e: json_data["response"] = e.details json_data["valid"] = False pass return HttpResponse(json.dumps(json_data), content_type="application/json")
account_media.creative_type = CREATIVE_TYPE.PREROLL account_media.save() # create a campaign campaign = Campaign(account) campaign.name = "Video tutorial test" # get the first funding instrument on the account campaign.funding_instrument_id = account.funding_instruments().first.id campaign.daily_budget_amount_local_micro = 1000000000 campaign.entity_status = ENTITY_STATUS.PAUSED campaign.start_time = datetime.utcnow() campaign.save() # create a line item with the VIDEO_VIEWS_PREROLL # objective and product_type MEDIA line_item = LineItem(account) line_item.objective = OBJECTIVE.VIDEO_VIEWS_PREROLL line_item.campaign_id = campaign.id line_item.name = 'Video tutorial example' line_item.product_type = 'MEDIA' line_item.placements = [PLACEMENT.ALL_ON_TWITTER] line_item.bid_amount_local_micro = 1000000 line_item.entity_status = ENTITY_STATUS.PAUSED line_item.categories = 'IAB1' line_item.save() from twitter_ads.http import Request resource = '/' + API_VERSION + '/accounts/18ce54bgxky/preroll_call_to_actions'.format( account_id=account.id)
campaign_2.daily_budget_amount_local_micro = 2000000 campaign_2.name = 'my second campaign' campaign_2.paused = True campaign_2.start_time = datetime.utcnow() campaigns_list = [campaign_1, campaign_2] Campaign.batch_save(account, campaigns_list) # modify the created campaigns campaign_1.name = 'my modified first campaign' campaign_2.name = 'my modified second campaign' Campaign.batch_save(account, campaigns_list) # create line items for campaign_1 line_item_1 = LineItem(account) line_item_1.campaign_id = campaign_1.id line_item_1.name = 'my first ad' line_item_1.product_type = PRODUCT.PROMOTED_TWEETS line_item_1.placements = [PLACEMENT.ALL_ON_TWITTER] line_item_1.objective = OBJECTIVE.TWEET_ENGAGEMENTS line_item_1.bid_amount_local_micro = 10000 line_item_1.paused = True line_item_2 = LineItem(account) line_item_2.campaign_id = campaign_1.id line_item_2.name = 'my second ad' line_item_2.product_type = PRODUCT.PROMOTED_TWEETS line_item_2.placements = [PLACEMENT.ALL_ON_TWITTER] line_item_2.objective = OBJECTIVE.TWEET_ENGAGEMENTS line_item_2.bid_amount_local_micro = 20000