/** * Creates an AdWordsUser from the test auth and settings files. * @param $defaultVersion the default version of the API the user should use * @return AdWordsUser the new user */ public static function CreateUser($defaultVersion = NULL) { $testDataPath = dirname(__FILE__) . '/../../../../../../test_data/'; $authFile = $testDataPath . 'test_auth.ini'; $settingsFile = $testDataPath . 'test_settings.ini'; $user = new AdWordsUser($authFile, NULL, NULL, NULL, NULL, NULL, NULL, $settingsFile); $user->SetDefaultVersion($defaultVersion); $user->LogDefaults(); return $user; }
public function addCampaign($name = 'Campaign #', $stategy_type = Core_Util_Adwords::STRATEGY_DEFAULT_TYPE) { $user = new AdWordsUser(); // Optionally, enable logging to capture the content of SOAP requests and // responses. $user->LogDefaults(); // Instantiate the desired service class by calling the get***Service method on // the AdWordsUser instance. $campaignService = $user->GetService('CampaignService', Core_Util_Adwords::ADWORDS_VERSION); // Create data objects and invoke methods on the service class instance. The // data objects and methods map directly to the data objects and requests for // the corresponding web service. // Create new campaign structure. $campaign = new Campaign(); $campaign->name = $name; $campaign->status = 'ACTIVE'; $campaign->biddingStrategyConfiguration = new BiddingStrategyConfiguration(); $campaign->biddingStrategyConfiguration->biddingStrategyType = $stategy_type; $budget_id = uniqid(); $budget = new Budget($budget_id); $budget->name = 'Budget #' . $budget_id; $budget->period = 'DAILY'; $budget->amount = new Money(1000); $budget->deliveryMethod = 'STANDARD'; $campaign->budget = $budget; //$campaign->budget = new Budget('123', 'default budget', 'DAILY', new Money(10000), 'STANDARD'); $operation = new CampaignOperation(); $operation->operand = $campaign; $operation->operator = 'ADD'; $operations[] = $operation; // Add campaign. $campaignReturnValue = $campaignService->mutate($operations); return $campaignReturnValue; /* foreach ($result->value as $campaign) { printf("Campaign with name '%s' and ID '%s' was added.\n", $campaign->name, $campaign->id); } */ }