Exemple #1
0
def new(request):
    """
    Returns a new campaign
    """
    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_name = request.GET.get("campaign", "")
    daily_budget = request.GET.get("daily_budget", "")
    account = client.accounts(account_id)
    # create your campaign
    json_data = {}
    try:
        campaign = Campaign(account)
        campaign.funding_instrument_id = account.funding_instruments().next(
        ).id
        campaign.daily_budget_amount_local_micro = int(daily_budget) * 1000
        campaign.name = campaign_name
        campaign.paused = True
        campaign.start_time = datetime.datetime.utcnow()
        campaign.save()
        json_data = {
            "valid": True,
            "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
        # passing as we send the json_data
        pass
    return HttpResponse(json.dumps(json_data), content_type="application/json")
Exemple #2
0
def new(request):
    """
    Returns a new campaign
    """
    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_name = request.GET.get("campaign", "")
    daily_budget = request.GET.get("daily_budget", "")
    account = client.accounts(account_id)
    # create your campaign
    json_data = {}
    try:
        campaign = Campaign(account)
        campaign.funding_instrument_id = account.funding_instruments().next().id
        campaign.daily_budget_amount_local_micro = int(daily_budget) * 1000
        campaign.name = campaign_name
        campaign.paused = True
        campaign.start_time = datetime.datetime.utcnow()
        campaign.save()
        json_data = {
            "valid": True,
            "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
        # passing as we send the json_data
        pass
    return HttpResponse(json.dumps(json_data), content_type="application/json")
video_id = video.id
print video_id

account_media = AccountMedia(account)
account_media.video_id = video_id
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()
ACCESS_TOKEN_SECRET = "user access token secret"
ADS_ACCOUNT = "ads account id"

# initialize the twitter ads api client
client = Client(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)

# load up the account instance
account = client.accounts(ADS_ACCOUNT)

# create two campaigns
campaign_1 = Campaign(account)
campaign_1.funding_instrument_id = account.funding_instruments().next().id
campaign_1.daily_budget_amount_local_micro = 1000000
campaign_1.name = "my first campaign"
campaign_1.paused = True
campaign_1.start_time = datetime.utcnow()

campaign_2 = Campaign(account)
campaign_2.funding_instrument_id = account.funding_instruments().next().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"
Exemple #5
0
ADS_ACCOUNT = 'ads account id'

# initialize the twitter ads api client
client = Client(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN,
                ACCESS_TOKEN_SECRET)

# load up the account instance
account = client.accounts(ADS_ACCOUNT)

# create two campaigns
campaign_1 = Campaign(account)
campaign_1.funding_instrument_id = account.funding_instruments().next().id
campaign_1.daily_budget_amount_local_micro = 1000000
campaign_1.name = 'my first campaign'
campaign_1.paused = True
campaign_1.start_time = datetime.utcnow()

campaign_2 = Campaign(account)
campaign_2.funding_instrument_id = account.funding_instruments().next().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'
Exemple #6
0
ACCESS_TOKEN_SECRET = 'EcXHIhWDD2xXe5GPoaWoNllMY3Z2wBhwM8XUdM9CkSaC9'
ACCOUNT_ID = '443463608'

# initialize the client
client = Client(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)

# load the advertiser account instance
account = client.accounts(ACCOUNT_ID)

# create your campaign
campaign = Campaign(account)
campaign.funding_instrument_id = account.funding_instruments().next().id
campaign.daily_budget_amount_local_micro = 1000000
campaign.name = 'my first campaign'
campaign.paused = True
campaign.start_time = datetime.datetime.utcnow()
campaign.save()


# create a line item for the campaign
line_item = LineItem(account)
line_item.campaign_id = campaign.id
line_item.name = 'my first ad'
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 = 10000
line_item.paused = True
line_item.save()

# add targeting criteria