예제 #1
0
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")
예제 #2
0
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")
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)
params = {
    'line_item_id': line_item.id,
    'call_to_action': 'WATCH_NOW',
    'call_to_action_url': 'https://www.my-cta-url.com'
}

# try, build and execute the request with error handling
try:
    response = Request(client, 'post', resource, params=params).perform()
except Error as e:
예제 #4
0
파일: test2.py 프로젝트: wangchenshu/test
# 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
targeting_criteria = TargetingCriteria(account)
targeting_criteria.line_item_id = line_item.id
targeting_criteria.targeting_type = 'LOCATION'
targeting_criteria.targeting_value = '00a8b25e420adc94'
targeting_criteria.save()