GoogleAPI Adwords Budget

来源:互联网 发布:xp网络共享一键设置 编辑:程序博客网 时间:2024/06/13 23:37

预算

预算状态:

isExplicitlyShared = true, 预算共享

isExplicitlyShared = false, 只能由一个广告系列使用


给广告系列分配预算


新的广告系列:

// Get the BudgetService.
BudgetServiceInterface budgetService =
    adWordsServices
.get(session, BudgetServiceInterface.class);

// Create a budget, which can be shared by multiple campaigns.
Budget sharedBudget = new Budget();
sharedBudget
.setName("Interplanetary Cruise #" + System.currentTimeMillis());
Money budgetAmount = new Money();
budgetAmount
.setMicroAmount(50000000L);
sharedBudget
.setAmount(budgetAmount);
sharedBudget
.setDeliveryMethod(BudgetBudgetDeliveryMethod.STANDARD);
sharedBudget
.setPeriod(BudgetBudgetPeriod.DAILY);
BudgetOperation budgetOperation = new BudgetOperation();
budgetOperation
.setOperand(sharedBudget);
budgetOperation
.setOperator(Operator.ADD);

// Execute the new budget operation and save the assigned budget ID.
Long budgetId =
    budgetService
.mutate(new BudgetOperation[] {budgetOperation}).getValue(0).getBudgetId();
Campaign campaign = new Campaign();
campaign
.setName("Interplanetary Cruise #" + System.currentTimeMillis());
campaign
.setStatus(CampaignStatus.PAUSED);
campaign
.setAdvertisingChannelType(AdvertisingChannelType.SEARCH);

// Set the bidding strategy configuration.
BiddingStrategyConfiguration biddingStrategyConfiguration =
   
new BiddingStrategyConfiguration();
biddingStrategyConfiguration
.setBiddingStrategyType(BiddingStrategyType.MANUAL_CPC);
campaign
.setBiddingStrategyConfiguration(biddingStrategyConfiguration);

// Only the budgetId should be set.
Budget budget = new Budget();
budget
.setBudgetId(budgetId);
campaign
.setBudget(budget);
CampaignServiceInterface campaignService =
    adWordsServices
.get(session, CampaignServiceInterface.class);
CampaignOperation operation = new CampaignOperation();
operation
.setOperand(campaign);
operation
.setOperator(Operator.ADD);
CampaignOperation[] operations = new CampaignOperation[] {operation};
CampaignReturnValue result = campaignService.mutate(operations);
改变广告系列的预算

CampaignService.mutate SET operation, and set the budget attribute of the campaign to a Budget object with its budgetId set to the ID of the existing budget (along with any other campaign fields that you might want to set). 


去掉预算

1.确保没有ENABLED or PAUSED广告在使用它

// Retrieve a budget with budget ID of interest
Long budgetId =  Long.parseLong("INSERT_BUDGET_ID_HERE");
Selector selector = new SelectorBuilder()
   
.fields(BudgetField.BudgetId, BudgetField.BudgetReferenceCount)
   
.orderAscBy(BudgetField.BudgetId)
   
.equals(BudgetField.BudgetId, budgetId.toString())
   
.build();
// (Code Excluded) Get a Budget object from the result of BudgetService.get
// Remove the budget only if its referenceCount == 0 (no campaigns are using it)
if (budget.getReferenceCount() == 0) {
   
BudgetServiceInterface budgetService =
        adWordsServices
.get(session, BudgetServiceInterface.class);
   
BudgetOperation operation = new BudgetOperation();
    operation
.setOperand(budget);
    operation
.setOperator(Operator.REMOVE);
   
BudgetOperation[] operations = new BudgetOperation[] {operation};
   
BudgetReturnValue result = budgetService.mutate(operations);
}
获取正在使用此预算的广告系列

Long budgetId =  Long.parseLong("INSERT_BUDGET_ID_HERE");
Selector selector = new SelectorBuilder()
   
.fields(CampaignField.Id, CampaignField.BudgetId)
   
.orderAscBy(CampaignField.Id)
   
.equals(CampaignField.BudgetId, budgetId.toString())
   
.build();
AWQL:

SELECT BudgetId, BudgetName, Amount, IsBudgetExplicitlyShared,
       
AssociatedCampaignId, Impressions
FROM BUDGET_PERFORMANCE_REPORT
WHERE
BudgetId = <YOUR_BUDGET_ID>
跟踪表现
 Budget Performance Report

0 0
原创粉丝点击