示例#1
0
 public function ConstructWithAccountAndCustomerId($wsdl, $username, $password, $token, $accountId, $customerId, $authenticationToken)
 {
     $thisClient = new ClientProxy($wsdl);
     $thisClient->authenticationToken = $authenticationToken;
     $thisClient->username = $username;
     $thisClient->password = $password;
     $thisClient->developerToken = $token;
     $thisClient->accountId = $accountId;
     $thisClient->customerId = $customerId;
     $thisClient->service = $thisClient->GetProxy($wsdl);
     return $thisClient;
 }
use BingAds\v10\CampaignManagement\CustomParameter;
// Specify the BingAds\Proxy objects that will be used.
use BingAds\Proxy\ClientProxy;
// Disable WSDL caching.
ini_set("soap.wsdl_cache_enabled", "0");
ini_set("soap.wsdl_cache_ttl", "0");
// Specify your credentials.
$UserName = "******";
$Password = "******";
$DeveloperToken = "<DeveloperTokenGoesHere>";
$CustomerId = "<CustomerIdGoesHere>";
$AccountId = "<AccountIdGoesHere>";
// Campaign Management WSDL
$wsdl = "https://campaign.api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/V10/CampaignManagementService.svc?singleWsdl";
try {
    $proxy = ClientProxy::ConstructWithAccountAndCustomerId($wsdl, $UserName, $Password, $DeveloperToken, $AccountId, null, null);
    // Specify one or more campaigns.
    $campaigns = array();
    $campaign = new Campaign();
    $campaign->Name = "Winter Clothing " . $_SERVER['REQUEST_TIME'];
    $campaign->Description = "Winter clothing line.";
    $campaign->BudgetType = BudgetLimitType::MonthlyBudgetSpendUntilDepleted;
    $campaign->MonthlyBudget = 1000.0;
    $campaign->TimeZone = "PacificTimeUSCanadaTijuana";
    $campaign->DaylightSaving = true;
    // Used with FinalUrls shown in the ads that we will add below.
    $campaign->TrackingUrlTemplate = "http://tracker.example.com/?season={_season}&promocode={_promocode}&u={lpurl}";
    $campaigns[] = $campaign;
    // Specify one or more ad groups.
    $adGroups = array();
    $endDate = new Date();
ini_set("soap.wsdl_cache_enabled", "0");
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.
function GetCampaignsByAccountId($customerId, $accountId)
{
    $GLOBALS['campaignProxy'] = ClientProxy::ConstructWithAccountAndCustomerId($GLOBALS['campaignWsdl'], $GLOBALS['UserName'], $GLOBALS['Password'], $GLOBALS['DeveloperToken'], $accountId, $customerId, null);
    $GLOBALS['proxy'] = $GLOBALS['campaignProxy'];
    $request = new GetCampaignsByAccountIdRequest();
    $request->AccountId = $accountId;
    return $GLOBALS['campaignProxy']->GetService()->GetCampaignsByAccountId($request)->Campaigns;
}