def new_targeting(request):
    """
    Creates a new
    """
    line_item_id = request.GET.get("line_item_id", "")
    account_id = request.GET.get("account_id", "")
    targeting_value = request.GET.get("targeting_value")
    targeting_type = "BEHAVIOR_EXPANDED"
    json_data = {}
    try:
        client = Client(settings.SOCIAL_AUTH_TWITTER_KEY,
                        settings.SOCIAL_AUTH_TWITTER_SECRET,
                        settings.TWITTER_ACCESS_TOKEN,
                        settings.TWITTER_ACCESS_TOKEN_SECRET)
        account = client.accounts(account_id)
        targeting_criteria = TargetingCriteria(account)
        targeting_criteria.line_item_id = line_item_id
        targeting_criteria.targeting_type = targeting_type
        targeting_criteria.targeting_value = targeting_value
        if targeting_value == "TAILORED_AUDIENCE":
            targeting_criteria.tailored_audience_type = "FLEXIBLE"
        targeting_criteria.save()
        json_data = {
            "valid": True,
            "account_id": account_id,
            "line_item_id": line_item_id,
            "targeting_value": targeting_value
        }
    except Error as e:
        json_data["response"] = e.details
        json_data["valid"] = False
        # passing to push the json_data to the browser
        pass
    return HttpResponse(json.dumps(json_data), content_type="application/json")
示例#2
0
def new_targeting(request):
    """
    Creates a new
    """
    line_item_id = request.GET.get("line_item_id", "")
    account_id = request.GET.get("account_id", "")
    targeting_value = request.GET.get("targeting_value")
    targeting_type = "BEHAVIOR_EXPANDED"
    json_data = {}
    try:
        client = Client(
            settings.SOCIAL_AUTH_TWITTER_KEY,
            settings.SOCIAL_AUTH_TWITTER_SECRET,
            settings.TWITTER_ACCESS_TOKEN,
            settings.TWITTER_ACCESS_TOKEN_SECRET)
        account = client.accounts(account_id)
        targeting_criteria = TargetingCriteria(account)
        targeting_criteria.line_item_id = line_item_id
        targeting_criteria.targeting_type = targeting_type
        targeting_criteria.targeting_value = targeting_value
        if targeting_value == "TAILORED_AUDIENCE":
            targeting_criteria.tailored_audience_type = "FLEXIBLE"
        targeting_criteria.save()
        json_data = {
            "valid": True,
            "account_id": account_id,
            "line_item_id": line_item_id,
            "targeting_value": targeting_value}
    except Error as e:
        json_data["response"] = e.details
        json_data["valid"] = False
        # passing to push the json_data to the browser
        pass
    return HttpResponse(json.dumps(json_data), content_type="application/json")
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
line_item_2.paused = True

line_items_list = [line_item_1, line_item_2]
LineItem.batch_save(account, line_items_list)

# create targeting criteria for line_item_1
targeting_criterion_1 = TargetingCriteria(account)
targeting_criterion_1.line_item_id = line_item_1.id
targeting_criterion_1.targeting_type = "LOCATION"
targeting_criterion_1.targeting_value = "00a8b25e420adc94"

targeting_criterion_2 = TargetingCriteria(account)
targeting_criterion_2.line_item_id = line_item_1.id
targeting_criterion_2.targeting_type = "PHRASE_KEYWORD"
targeting_criterion_2.targeting_value = "righteous dude"

targeting_criteria_list = [targeting_criterion_1, targeting_criterion_2]
TargetingCriteria.batch_save(account, targeting_criteria_list)

targeting_criterion_1.to_delete = True
targeting_criterion_2.to_delete = True
示例#4
0
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
line_item_2.paused = True

line_items_list = [line_item_1, line_item_2]
LineItem.batch_save(account, line_items_list)

# create targeting criteria for line_item_1
targeting_criterion_1 = TargetingCriteria(account)
targeting_criterion_1.line_item_id = line_item_1.id
targeting_criterion_1.targeting_type = 'LOCATION'
targeting_criterion_1.targeting_value = '00a8b25e420adc94'

targeting_criterion_2 = TargetingCriteria(account)
targeting_criterion_2.line_item_id = line_item_1.id
targeting_criterion_2.targeting_type = 'PHRASE_KEYWORD'
targeting_criterion_2.targeting_value = 'righteous dude'

targeting_criteria_list = [targeting_criterion_1, targeting_criterion_2]
TargetingCriteria.batch_save(account, targeting_criteria_list)

targeting_criterion_1.to_delete = True
targeting_criterion_2.to_delete = True
示例#5
0
# 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.entity_status = ENTITY_STATUS.PAUSED
campaign.start_time = 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.entity_status = ENTITY_STATUS.PAUSED
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()
      "line_item_id":"1a2bc",
      "targeting_value":"digital",
      "operator_type":"EQ",
      "targeting_type":"BROAD_KEYWORD"
    }
  },
  {  
    "operation_type":"Create",
    "params":{  
      "line_item_id":"1a2bc",
      "targeting_value":"analog",
      "operator_type":"NE",
      "targeting_type":"BROAD_KEYWORD"
    }
  }
]
"""
with open('targeting.json', 'r') as f:
    targeting_data = json.load(f)

targeting = []
for obj in targeting_data:
    tc = TargetingCriteria(account)
    tc.line_item_id = obj['params']['line_item_id']
    tc.operator_type = obj['params']['operator_type']
    tc.targeting_type = obj['params']['targeting_type']
    tc.targeting_value = obj['params']['targeting_value']
    targeting.append(tc)

TargetingCriteria.batch_save(account, targeting)
示例#7
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()
      "line_item_id":"1a2bc",
      "targeting_value":"digital",
      "operator_type":"EQ",
      "targeting_type":"BROAD_KEYWORD"
    }
  },
  {  
    "operation_type":"Create",
    "params":{  
      "line_item_id":"1a2bc",
      "targeting_value":"analog",
      "operator_type":"NE",
      "targeting_type":"BROAD_KEYWORD"
    }
  }
]
"""
with open('targeting.json', 'r') as f:
    targeting_data = json.load(f)

targeting = []
for obj in targeting_data:
    tc = TargetingCriteria(account)
    tc.line_item_id = obj['params']['line_item_id']
    tc.operator_type = obj['params']['operator_type']
    tc.targeting_type = obj['params']['targeting_type']
    tc.targeting_value = obj['params']['targeting_value']
    targeting.append(tc)

TargetingCriteria.batch_save(account, targeting)