private static Campaign createCampaign ( AdWordsServicesInterface adWordsServices , AdWordsSession session , Budget budget ) throws RemoteException , ApiException { // Get the CampaignService. CampaignServiceInterface campaignService = adWordsServices . get ( session , CampaignServiceInterface . class ) ; // Create campaign. Campaign campaign = new Campaign ( ) ; campaign . setName ( "Interplanetary Cruise #" + System . currentTimeMillis ( ) ) ; campaign . setAdvertisingChannelType ( AdvertisingChannelType . SEARCH ) ; // Recommendation: Set the campaign to PAUSED when creating it to prevent // the ads from immediately serving. Set to ENABLED once you've added // targeting and the ads are ready to serve. campaign . setStatus ( CampaignStatus . PAUSED ) ; BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration ( ) ; biddingStrategyConfiguration . setBiddingStrategyType ( BiddingStrategyType . MANUAL_CPC ) ; campaign . setBiddingStrategyConfiguration ( biddingStrategyConfiguration ) ; // Only the budgetId should be sent, all other fields will be ignored by CampaignService. Budget campaignBudget = new Budget ( ) ; campaignBudget . setBudgetId ( budget . getBudgetId ( ) ) ; campaign . setBudget ( campaignBudget ) ; // Required: Set the campaign's Dynamic Search Ads settings. DynamicSearchAdsSetting dynamicSearchAdsSetting = new DynamicSearchAdsSetting ( ) ; // Required: Set the domain name and language. dynamicSearchAdsSetting . setDomainName ( "example.com" ) ; dynamicSearchAdsSetting . setLanguageCode ( "en" ) ; // Set the campaign settings. campaign . setSettings ( new Setting [ ] { dynamicSearchAdsSetting } ) ; // Optional: Set the start date. campaign . setStartDate ( new DateTime ( ) . plusDays ( 1 ) . toString ( "yyyyMMdd" ) ) ; // Optional: Set the end date. campaign . setEndDate ( new DateTime ( ) . plusYears ( 1 ) . toString ( "yyyyMMdd" ) ) ; // Create the operation. CampaignOperation operation = new CampaignOperation ( ) ; operation . setOperand ( campaign ) ; operation . setOperator ( Operator . ADD ) ; // Add the campaign. Campaign newCampaign = campaignService . mutate ( new CampaignOperation [ ] { operation } ) . getValue ( 0 ) ; // Display the results. System . out . printf ( "Campaign with name '%s' and ID %d was added.%n" , newCampaign . getName ( ) , newCampaign . getId ( ) ) ; return newCampaign ; }
Creates the campaign .