在Google Adwords中,您如何以编程方式更改预算?

bug*_*net 1 google-adwords adwords-budgetservice

可悲的是,没有任何示例(我已经研究了一段时间)。

我希望能够以编程方式修改广告系列的预算。我可以看到BudgetService存在,但是我不知道如何(或去哪里找到方法)获取预算ID或预算名称。

我猜想人们必须查询广告系列的预算,从该budgetid导出,然后在BudgetService请求中使用它。是这样吗 如果没有,那怎么办?

Bec*_*llo 5

我不知道您使用的是哪种语言/客户端库,但是以下假定适用于Ruby,前提是您已经处理了配置和授权。我想在其他任何客户端库中它都非常相似。

首先,建立一个API连接。

adwords = AdwordsApi::Api.new
Run Code Online (Sandbox Code Playgroud)

使用CampaignService获取预算的ID。您还可以了解预算的当前金额和期间(DAILY,MONTHLY等)。

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)
Run Code Online (Sandbox Code Playgroud)

从响应中提取预算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])
Run Code Online (Sandbox Code Playgroud)