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")
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")