Bing广告API客户注册在php中

时间:2014-10-26 21:20:36

标签: php xml api soap bing

我需要php soap中的帮助来发送以下链接中提供的xml请求。

http://msdn.microsoft.com/en-us/library/dn451287.aspx

另外,不知道发送请求的链接是什么。

1 个答案:

答案 0 :(得分:0)

    // For Customer managment use the wsdl "https://clientcenter.api.bingads.microsoft.com/Api/CustomerManagement/v9/CustomerManagementService.svc?singleWsdl"         


// Include files from bing client lib here - Or better yet - use composer to autoload - 

            use BingAds\Proxy\ClientProxy; 
            use BingAds\CustomerManagement\Address;
            use BingAds\CustomerManagement\Customer;
            use BingAds\CustomerManagement\Industry;
            use BingAds\CustomerManagement\LanguageType;
            use BingAds\CustomerManagement\AdvertiserAccount;
            use BingAds\CustomerManagement\Account;
            use BingAds\CustomerManagement\CurrencyType;
            use BingAds\CustomerManagement\SignupCustomerRequest;
            use BingAds\CustomerManagement\AccountType; 


        // you should download the client lib - then should be able to do like so -
        // i assume that you have developer token, and access token already for re seller account already ...   

    // also NOTE the soap Var advertiser account - or this won't work - you will get abstract class error ... 

        // Disable WSDL caching. 

        ini_set("soap.wsdl_cache_enabled", "0"); 
        ini_set("soap.wsdl_cache_ttl", "0"); 

        // Specify your credentials. 

        $UserName = "<UserNameGoesHere>"; 
        $Password = "<PasswordGoesHere>"; 
        $DeveloperToken = "DeveloperTokenGoesHere>";  
        $AccountId = <AccountIdGoesHere>; 


         $proxy = ClientProxy::ConstructWithAccountAndCustomerId($wsdl, $UserName, $Password, $DeveloperToken, $AccountId, null, null); 



                $address = new Address(); 
                $address->CountryCode = 'US';
                $address->City = 'Some CIty';
                $address->Line1 = 'Some Address';
                $address->PostalCode = 60010;
                $address->StateOrProvince = 'IL';

                // create customer 
                $customer = new Customer(); 
                $customer->CustomerAddress = $address;
                $customer->Industry = Industry::Automotive; 
                $customer->MarketCountry = 'US'; 
                $customer->MarketLanguage = LanguageType::English;
                $customer->Name = 'No Account';  


                // create advertiser 
                $advertiseAccount = new AdvertiserAccount();
                $advertiseAccount->AccountType = AccountType::Advertiser;
                $advertiseAccount->Type = CurrencyType::USDollar;
                $advertiseAccount->CurrencyType = CurrencyType::USDollar;
                $advertiseAccount->Name ='No Account';
                $advertiseAccount->PaymentMethodType = NULL; 


                $request = new SignupCustomerRequest();
                $request->Customer = $customer; 
                $request->Account = new \soapVar($advertiseAccount, SOAP_ENC_OBJECT, 'AdvertiserAccount', $proxy->getNamespace() . '/Entities');
                $request->ParentCustomerId = \Models\Bingads\User\BingAuth::CUSTOMER_ID_RS;
                $request->ApplicationScope = ApplicationType::Advertiser;

                try{
                    $response = $proxy->GetService()->SignupCustomer($request);
                }catch(\Exception $e){
                    error_log($e->getMessage()); 
                }

                return $response;