ini_set("soap.wsdl_cache_ttl", "0"); // Specify your credentials. $UserName = "******"; $Password = "******"; $DeveloperToken = "<DeveloperTokenGoesHere>"; $CustomerId = "<CustomerIdGoesHere>"; $AccountId = "<AccountIdGoesHere>"; $GLOBALS['proxy'] = null; $GLOBALS['adInsightWsdl'] = "https://adinsight.api.bingads.microsoft.com/Api/Advertiser/AdInsight/V10/AdInsightService.svc?singleWsdl"; $GLOBALS['adInsightProxy'] = null; $GLOBALS['campaignWsdl'] = "https://campaign.api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/V10/CampaignManagementService.svc?singleWsdl"; $GLOBALS['campaignProxy'] = null; try { $GLOBALS['adInsightProxy'] = ClientProxy::ConstructWithAccountId($GLOBALS['adInsightWsdl'], $UserName, $Password, $DeveloperToken, $AccountId, null); $GLOBALS['campaignProxy'] = ClientProxy::ConstructWithAccountId($GLOBALS['campaignWsdl'], $UserName, $Password, $DeveloperToken, $AccountId, null); $campaigns = GetCampaignsByAccountId($AccountId, CampaignType::SearchAndContent . ' ' . CampaignType::Shopping); foreach ($campaigns->Campaign as $campaign) { $opportunities = GetBudgetOpportunities($campaign->Id); OutputBudgetOpportunities($opportunities, $campaign->Id); } } catch (SoapFault $e) { // Output the last request/response. print "\nLast SOAP request/response:\n"; print $GLOBALS['proxy']->GetWsdl() . "\n"; print $GLOBALS['proxy']->GetService()->__getLastRequest() . "\n"; print $GLOBALS['proxy']->GetService()->__getLastResponse() . "\n"; print "\n\n"; // Ad Insight and Campaign Management service operations can throw AdApiFaultDetail. if (isset($e->detail->AdApiFaultDetail)) { // Log this fault. print "The operation failed with the following faults:\n";
function PrintCustomers($customers) { foreach ($customers->Customer as $cust) { if (!empty($cust)) { printf("CustomerId: %d\n", $cust->Id); $aInfos = GetAccountsInfo($cust->Id); // Print a list of all accounts managed by the customer foreach ($aInfos->AccountInfo as $aInfo) { if (!empty($aInfo)) { printf("CustomerAccountId: %d\n", $aInfo->Id); $campaigns = GetCampaignsByAccountId($cust->Id, $aInfo->Id); foreach ($campaigns->Campaign as $campaign) { printf("CampaignId: %d\n", $campaign->Id); } } } } print "\n"; } }