Dear All,

I am quite new with the AdWords API. I have the need to update the budget 
for a list of campaigns. I have to assign a new individual budget, removing 
the previous shared budget.

Up to now I tried to follow the instructions present 
here, https://developers.google.com/adwords/api/docs/guides/budgets, but 
without results.

In the row 70 of my code, i correctly see the new budget, but on the 
AdWords platform I cannot see the result.

I have to change the budget for more than 2000 campaigns, can someone tell 
me where and why my code does not work?

Many many thanks.

Roberto

PS: In the code i iterate trough all the campaigns, because at the moment I 
am not able to select a campaign by name...
________________________________________________________________________________________________________________________________________________________

package My_Test;

import java.rmi.RemoteException;

import com.google.api.ads.adwords.axis.factory.AdWordsServices;
import com.google.api.ads.adwords.axis.utils.v201509.SelectorBuilder;
import com.google.api.ads.adwords.axis.v201509.cm.ApiException;
import com.google.api.ads.adwords.axis.v201509.cm.Budget;
import 
com.google.api.ads.adwords.axis.v201509.cm.BudgetBudgetDeliveryMethod;
import com.google.api.ads.adwords.axis.v201509.cm.BudgetBudgetPeriod;
import com.google.api.ads.adwords.axis.v201509.cm.BudgetOperation;
import com.google.api.ads.adwords.axis.v201509.cm.BudgetServiceInterface;
import com.google.api.ads.adwords.axis.v201509.cm.Campaign;
import com.google.api.ads.adwords.axis.v201509.cm.CampaignOperation;
import com.google.api.ads.adwords.axis.v201509.cm.CampaignPage;
import com.google.api.ads.adwords.axis.v201509.cm.CampaignReturnValue;
import com.google.api.ads.adwords.axis.v201509.cm.CampaignServiceInterface;
import com.google.api.ads.adwords.axis.v201509.cm.Money;
import com.google.api.ads.adwords.axis.v201509.cm.Operator;
import com.google.api.ads.adwords.axis.v201509.cm.Selector;
import com.google.api.ads.adwords.lib.client.AdWordsSession;
import 
com.google.api.ads.adwords.lib.selectorfields.v201509.cm.CampaignField;
import com.google.api.ads.common.lib.auth.OfflineCredentials;
import com.google.api.ads.common.lib.auth.OfflineCredentials.Api;
import com.google.api.ads.common.lib.conf.ConfigurationLoadException;
import com.google.api.ads.common.lib.exception.OAuthException;
import com.google.api.ads.common.lib.exception.ValidationException;
import com.google.api.client.auth.oauth2.Credential;

public class Budget_Assignetor{
public static void main(String[] args) throws OAuthException, 
ValidationException, ConfigurationLoadException, ApiException, 
RemoteException { 
Credential oAuth2Credential = new 
OfflineCredentials.Builder().forApi(Api.ADWORDS).fromFile().build().generateCredential();//
 
Generate a refreshable OAuth2 credential.
   AdWordsServices adWordsServices = new AdWordsServices();
AdWordsSession session = new 
AdWordsSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();//
 
Construct an AdWordsSession.
BudgetServiceInterface budgetService =  adWordsServices.get(session, 
BudgetServiceInterface.class);
Budget individualBudget = new Budget();
individualBudget.setName("New Budget 1000 euro per day");
Money budgetAmount = new Money();
budgetAmount.setMicroAmount(1000000000L);
individualBudget.setAmount(budgetAmount);
individualBudget.setIsExplicitlyShared(false);
individualBudget.setDeliveryMethod(BudgetBudgetDeliveryMethod.STANDARD);
individualBudget.setPeriod(BudgetBudgetPeriod.DAILY);
BudgetOperation budgetOperation = new BudgetOperation();
budgetOperation.setOperand(individualBudget);
budgetOperation.setOperator(Operator.ADD); 
Long budgetId =  budgetService.mutate(new BudgetOperation[] 
{budgetOperation}).getValue(0).getBudgetId();
individualBudget.setBudgetId(budgetId);
int PAGE_SIZE = 100;
   CampaignServiceInterface campaignService = adWordsServices.get(session, 
CampaignServiceInterface.class);
   int offset = 0;
   // Create selector.
   SelectorBuilder builder = new SelectorBuilder();
   Selector selector = builder.fields(CampaignField.Id, 
CampaignField.Name).orderAscBy(CampaignField.Name).offset(offset).limit(PAGE_SIZE).build();
   CampaignPage page = null;
   
   do {
     page = campaignService.get(selector);
     if (page.getEntries() != null) {
       for (Campaign campaign : page.getEntries()) {
           if(campaign.getName().equals("Naturdiet | Headterm | BMM")) {
            campaign.setBudget(individualBudget);
            System.out.println(campaign.getName() + "   " + 
campaign.getBudget().getName());
               CampaignOperation operation = new CampaignOperation();
               operation.setOperand(campaign);
               operation.setOperator(Operator.SET);
               CampaignOperation[] operations = new CampaignOperation[] 
{operation};
               CampaignReturnValue result = 
campaignService.mutate(operations);
           }
       }
     }
     offset += PAGE_SIZE;
     selector = builder.increaseOffsetBy(PAGE_SIZE).build();
   } 
   while (offset < page.getTotalNumEntries()); 
}
}

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/133a3e46-e711-4df1-9a42-f2cf11cc621c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to