可悲的是,没有这方面的例子(我已经挖了一段时间了。)
我希望能够以编程方式修改广告系列的预算。我可以看到BudgetService存在,但我不知道如何(或在何处去了解如何)获取预算的ID或预算的名称。
我猜测,必须查询广告系列的预算,从budgetId派生,然后在BudgetService请求中使用它。是这样的吗?如果不是,那又怎么样?
答案 0 :(得分:4)
我不知道您使用的是哪种语言/客户端库,但以下内容适用于Ruby,假设您已经处理了配置和授权。我想它在任何其他客户端库中都会非常相似。
首先,建立API连接。
adwords = AdwordsApi::Api.new
使用CampaignService获取预算的ID。您还可以了解预算的当前金额和期限(每天,每月等)。
campaign_srv = adwords.service(:CampaignService, API_VERSION)
selector = {
fields: ['Id', 'Name', 'BudgetId', 'BudgetName', 'Amount', 'Period'],
predicates: [
{field: 'Id', operator: 'EQUALS', values: [CAMPAIGN_ID]}
]
}
campaign_response = campaign_srv.get(selector)
从响应中提取预算的ID,并使用BudgetService来更改金额。
budget_id = response[:entries][0][:budget][:budget_id]
budget_srv = adwords.service(:BudgetService, API_VERSION)
operation = {
operator: 'SET',
operand: {
id: budget_id,
amount: DESIRED_AMOUNT_IN_LOCAL_CURRENCY_FOR_ACCOUNT
}
}
budget_response = budget_srv.mutate([operation])
答案 1 :(得分:2)
Google的大多数文档都是关于Shared Budgets
的,而不是关于设置单个广告系列预算的。要设置单个广告系列预算,您仍然需要使用BudgetService
并创建一个BudgetId
,但是将isExplicitlyShared
设置为false
。将共享设置设置为false
不会创建共享预算,而是创建一个预算对象,该对象将设置单个广告系列预算。下面的Python示例:
from googleads import adwords
client = adwords.AdWordsClient.LoadFromStorage('<PATH_TO_YOUR_SERVICE_ACCOUNT>')
client.SetClientCustomerId('<YOUR_ADWORDS_ACCOUNT_ID>')
campaign_id = '<YOUR_CAMPAIGN_ID>'
def main():
# Initialize both campaign and budget services
campaign_service = client.GetService('CampaignService', version='v201809')
budget_service = client.GetService('BudgetService', version='v201809')
# Create a budget ID with no name, specify that it is not a shared budget
# Establish budget as a micro amount
budget = {
'name': None,
'isExplicitlyShared': 'false',
'amount': {
'microAmount': 80000000
}
}
budget_operations = [{
'operator': 'ADD',
'operand': budget
}]
budget_id = budget_service.mutate(budget_operations)['value'][0]['budgetId']
# Construct operations and update campaign.
operations = [{
'operator': 'SET',
'operand': {
'id': campaign_id,
'budget': {
'budgetId': budget_id
}
}
}]
campaigns = campaign_service.mutate(operations)
答案 2 :(得分:0)
更新预算的PHP功能,GoogleApiAdsAdWords,v201609
function GetCampaignAndUpdateBudgetExample(AdWordsUser $user, $campaignId)
{
// Get the service, which loads the required classes.
$campaignService = $user->GetService('CampaignService', ADWORDS_VERSION);
// Create selector.
$selector = new Selector();
$selector->fields = array('Id', 'Name', 'BudgetId', 'BudgetName', 'Amount');
$selector->predicates[] = new Predicate('CampaignId', 'EQUALS', array($campaignId));
$selector->ordering[] = new OrderBy('Name', 'ASCENDING');
// Create paging controls.
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
// Make the get request.
$page = $campaignService->get($selector);
// Display results.
if (isset($page->entries[0]))
{
$campaign = $page->entries[0];
printf("Campaign with name '%s' and ID '%s' and budget ID '%s' and budget Name '%s' was found.\n", $campaign->name, $campaign->id, $campaign->budget->budgetId, $campaign->budget->name);
// Get the BudgetService, which loads the required classes.
$budget_service = $user->GetService('BudgetService', ADWORDS_VERSION);
// Create the shared budget (required).
$budget = new Budget();
$budget->budgetId = $campaign->budget->budgetId;
$budget->amount = new Money(20000000);
$budget->deliveryMethod = 'STANDARD';
// Create operation.
$budet_operation = new BudgetOperation();
$budet_operation->operand = $budget;
$budet_operation->operator = 'SET';
// Make the mutate request.
$budget_service_result = $budget_service->mutate([$budet_operation]);
$budget_result = $budget_service_result->value[0];
printf("Budget with name '%s' and ID '%s' updated.\n", $budget_result->name, $budget_result->budgetId);
}
else
{
print "No campaigns were found.\n";
}
}