public void OutputAdvertiserAccount(AdvertiserAccount dataObject)
 {
     if (null != dataObject)
     {
         OutputStatusMessage(string.Format("BillToCustomerId: {0}", dataObject.BillToCustomerId));
         OutputStatusMessage(string.Format("CurrencyCode: {0}", dataObject.CurrencyCode));
         OutputStatusMessage(string.Format("AccountFinancialStatus: {0}", dataObject.AccountFinancialStatus));
         OutputStatusMessage(string.Format("Id: {0}", dataObject.Id));
         OutputStatusMessage(string.Format("Language: {0}", dataObject.Language));
         OutputStatusMessage(string.Format("LastModifiedByUserId: {0}", dataObject.LastModifiedByUserId));
         OutputStatusMessage(string.Format("LastModifiedTime: {0}", dataObject.LastModifiedTime));
         OutputStatusMessage(string.Format("Name: {0}", dataObject.Name));
         OutputStatusMessage(string.Format("Number: {0}", dataObject.Number));
         OutputStatusMessage(string.Format("ParentCustomerId: {0}", dataObject.ParentCustomerId));
         OutputStatusMessage(string.Format("PaymentMethodId: {0}", dataObject.PaymentMethodId));
         OutputStatusMessage(string.Format("PaymentMethodType: {0}", dataObject.PaymentMethodType));
         OutputStatusMessage(string.Format("PrimaryUserId: {0}", dataObject.PrimaryUserId));
         OutputStatusMessage(string.Format("AccountLifeCycleStatus: {0}", dataObject.AccountLifeCycleStatus));
         OutputStatusMessage(string.Format("TimeStamp: {0}", dataObject.TimeStamp));
         OutputStatusMessage(string.Format("TimeZone: {0}", dataObject.TimeZone));
         OutputStatusMessage(string.Format("PauseReason: {0}", dataObject.PauseReason));
         OutputArrayOfKeyValuePairOfstringstring(dataObject.ForwardCompatibilityMap);
         OutputArrayOfCustomerInfo(dataObject.LinkedAgencies);
         OutputStatusMessage(string.Format("SalesHouseCustomerId: {0}", dataObject.SalesHouseCustomerId));
         OutputArrayOfKeyValuePairOfstringstring(dataObject.TaxInformation);
         OutputStatusMessage(string.Format("BackUpPaymentInstrumentId: {0}", dataObject.BackUpPaymentInstrumentId));
         OutputStatusMessage(string.Format("BillingThresholdAmount: {0}", dataObject.BillingThresholdAmount));
         OutputAddress(dataObject.BusinessAddress);
         OutputStatusMessage(string.Format("AutoTagType: {0}", dataObject.AutoTagType));
         OutputStatusMessage(string.Format("SoldToPaymentInstrumentId: {0}", dataObject.SoldToPaymentInstrumentId));
     }
 }
        public async Task <UpdateAccountResponse> UpdateAccountAsync(
            AdvertiserAccount account)
        {
            var request = new UpdateAccountRequest
            {
                Account = account
            };

            return(await CustomerManagementService.CallAsync((s, r) => s.UpdateAccountAsync(r), request));
        }
コード例 #3
0
        public IActionResult AccountPost(Token token)
        {
            AdvertiserAccount account = new AdvertiserAccount();

            try
            {
                Microsoft.BingAds.Authentication authentication = AuthenticateWithOAuth(token);

                // Most Bing Ads service operations require account and customer ID.
                // This utiltiy operation sets the global authorization data instance
                // to the first account that the current authenticated user can access.
                IList <AdvertiserAccount> accounts = SetAuthorizationDataAsync(authentication, token.DeveloperToken).Result;
                account = accounts[0];

                // You can extend the console app with the examples library at:
                // https://github.com/BingAds/BingAds-dotNet-SDK/tree/master/examples/BingAdsExamples
            }
            // Catch authentication exceptions
            catch (OAuthTokenRequestException ex)
            {
                OutputStatusMessage(string.Format("OAuthTokenRequestException Message:\n{0}", ex.Message));
                if (ex.Details != null)
                {
                    OutputStatusMessage(string.Format("OAuthTokenRequestException Details:\nError: {0}\nDescription: {1}",
                                                      ex.Details.Error, ex.Details.Description));
                }
            }
            // Catch Customer Management service exceptions
            catch (FaultException <AdApiFaultDetail> ex)
            {
                OutputStatusMessage(string.Join("; ", ex.Detail.Errors.Select(error =>
                {
                    if ((error.Code == 105) || (error.Code == 106))
                    {
                        return("Authorization data is missing or incomplete for the specified environment.\n" +
                               "To run the examples switch users or contact support for help with the following error.\n");
                    }
                    return(string.Format("{0}: {1}", error.Code, error.Message));
                })));
                OutputStatusMessage(string.Join("; ",
                                                ex.Detail.Errors.Select(error => string.Format("{0}: {1}", error.Code, error.Message))));
            }
            catch (FaultException <Microsoft.BingAds.V12.CustomerManagement.ApiFault> ex)
            {
                OutputStatusMessage(string.Join("; ",
                                                ex.Detail.OperationErrors.Select(error => string.Format("{0}: {1}", error.Code, error.Message))));
            }
            catch (HttpRequestException ex)
            {
                OutputStatusMessage(ex.Message);
            }

            return(View(account));
        }
        public async Task <SignupCustomerResponse> SignupCustomerAsync(
            Customer customer,
            AdvertiserAccount account,
            long?parentCustomerId)
        {
            var request = new SignupCustomerRequest
            {
                Customer         = customer,
                Account          = account,
                ParentCustomerId = parentCustomerId
            };

            return(await CustomerManagementService.CallAsync((s, r) => s.SignupCustomerAsync(r), request));
        }
コード例 #5
0
        public AddPrepayAccountResponse AddPrepayAccount(ApiAuthentication auth, AdvertiserAccount prePayAccount)
        {
            var request = new AddPrepayAccountRequest
            {
                Account = prePayAccount
            };

            try
            {
                SetAuthHelper.SetAuth(auth, request);

                return(Check().AddPrepayAccount(request));
            }
            catch (Exception ex)
            {
                Log(new LogEventArgs(ServiceType.CustomerManagement, "AddPrepayAccount", ex.Message, new { Request = request }, ex));
            }

            return(null);
        }
コード例 #6
0
        public async override Task RunAsync(AuthorizationData authorizationData)
        {
            try
            {
                ApiEnvironment environment = ((OAuthDesktopMobileAuthCodeGrant)authorizationData.Authentication).Environment;

                CustomerManagementExampleHelper CustomerManagementExampleHelper = new CustomerManagementExampleHelper(
                    OutputStatusMessageDefault: this.OutputStatusMessage);
                CustomerManagementExampleHelper.CustomerManagementService = new ServiceClient <ICustomerManagementService>(
                    authorizationData: authorizationData,
                    environment: environment);

                OutputStatusMessage("-----\nGetUser:"******"User:"******"CustomerRoles:");
                CustomerManagementExampleHelper.OutputArrayOfCustomerRole(getUserResponse.CustomerRoles);

                // Only a user with the aggregator role (33) can sign up new customers.
                // If the user does not have the aggregator role, then do not continue.

                if (!getUserResponse.CustomerRoles.Select(role => role.RoleId).Contains(33))
                {
                    OutputStatusMessage("Only a user with the aggregator role (33) can sign up new customers.");
                    return;
                }

                var customer = new Customer
                {
                    // The primary business segment of the customer, for example, automotive, food, or entertainment.
                    Industry = Industry.Other,

                    // The primary country where the customer operates.
                    MarketCountry = "US",

                    // The primary language that the customer uses.
                    MarketLanguage = LanguageType.English,

                    // The name of the customer.
                    Name = "Child Customer " + DateTime.UtcNow,
                };

                var account = new AdvertiserAccount
                {
                    // The location where your business is legally registered.
                    // The business address is used to determine your tax requirements.
                    BusinessAddress = new Address
                    {
                        BusinessName    = "Contoso",
                        City            = "Redmond",
                        Line1           = "One Microsoft Way",
                        CountryCode     = "US",
                        PostalCode      = "98052",
                        StateOrProvince = "WA",
                    },

                    // The type of currency that is used to settle the account.
                    // The service uses the currency information for billing purposes.
                    CurrencyCode = CurrencyCode.USD,

                    // The name of the account.
                    Name = "Child Account " + DateTime.UtcNow,

                    // The identifier of the customer that owns the account.
                    ParentCustomerId = (long)user.CustomerId,

                    // The TaxId (VAT identifier) is optional. If specified, The VAT identifier must be valid
                    // in the country that you specified in the BusinessAddress element. Without a VAT registration
                    // number or exemption certificate, taxes might apply based on your business location.
                    TaxInformation = null,

                    // The default time-zone for campaigns in this account.
                    TimeZone = TimeZoneType.PacificTimeUSCanadaTijuana,
                };

                // Signup a new customer and account for the reseller.
                OutputStatusMessage("-----\nSignupCustomer:");
                var signupCustomerResponse = await CustomerManagementExampleHelper.SignupCustomerAsync(
                    customer : customer,
                    account : account,
                    parentCustomerId : user.CustomerId);

                OutputStatusMessage("New Customer and Account:");

                // This is the identifier that you will use to set the CustomerId
                // element in most of the Bing Ads API service operations.
                OutputStatusMessage(string.Format("\tCustomerId: {0}", signupCustomerResponse.CustomerId));

                // The read-only system-generated customer number that is used in the Bing Ads web application.
                // The customer number is of the form, Cnnnnnnn, where nnnnnnn is a series of digits.
                OutputStatusMessage(string.Format("\tCustomerNumber: {0}", signupCustomerResponse.CustomerNumber));

                // This is the identifier that you will use to set the AccountId and CustomerAccountId
                // elements in most of the Bing Ads API service operations.
                OutputStatusMessage(string.Format("\tAccountId: {0}", signupCustomerResponse.AccountId));

                // The read-only system generated account number that is used to identify the account in the Bing Ads web application.
                // The account number has the form xxxxxxxx, where xxxxxxxx is a series of any eight alphanumeric characters.
                OutputStatusMessage(string.Format("\tAccountNumber: {0}", signupCustomerResponse.AccountNumber));
            }
            // Catch authentication exceptions
            catch (OAuthTokenRequestException ex)
            {
                OutputStatusMessage(string.Format("Couldn't get OAuth tokens. Error: {0}. Description: {1}", ex.Details.Error, ex.Details.Description));
            }
            // Catch Customer Management service exceptions
            catch (FaultException <Microsoft.BingAds.V13.CustomerManagement.AdApiFaultDetail> ex)
            {
                OutputStatusMessage(string.Join("; ", ex.Detail.Errors.Select(error => string.Format("{0}: {1}", error.Code, error.Message))));
            }
            catch (FaultException <Microsoft.BingAds.V13.CustomerManagement.ApiFault> ex)
            {
                OutputStatusMessage(string.Join("; ", ex.Detail.OperationErrors.Select(error => string.Format("{0}: {1}", error.Code, error.Message))));
            }
            catch (Exception ex)
            {
                OutputStatusMessage(ex.Message);
            }
        }
コード例 #7
0
        public async override Task RunAsync(AuthorizationData authorizationData)
        {
            try
            {
                ApiEnvironment environment = ((OAuthDesktopMobileAuthCodeGrant)authorizationData.Authentication).Environment;

                CustomerManagementExampleHelper CustomerManagementExampleHelper =
                    new CustomerManagementExampleHelper(this.OutputStatusMessage);
                CustomerManagementExampleHelper.CustomerManagementService =
                    new ServiceClient <ICustomerManagementService>(authorizationData, environment);

                var getUserResponse = await CustomerManagementExampleHelper.GetUserAsync(null, true);

                var user = getUserResponse.User;

                // Only a user with the aggregator role (33) can sign up new customers.
                // If the user does not have the aggregator role, then do not continue.
                if (!getUserResponse.CustomerRoles.Select(role => role.RoleId).Contains(33))
                {
                    OutputStatusMessage("Only a user with the aggregator role (33) can sign up new customers.");
                    return;
                }

                // For Customer.CustomerAddress and Account.BusinessAddress, you can use the same address
                // as your aggregator user, although you must set Id and TimeStamp to null.
                var userAddress = user.ContactInfo.Address;
                userAddress.Id        = null;
                userAddress.TimeStamp = null;

                var customer = new Customer
                {
                    // The primary business segment of the customer, for example, automotive, food, or entertainment.
                    Industry = Industry.Other,

                    // The primary country where the customer operates. This country will be the
                    // default country for ad groups in the customer’s campaigns.
                    MarketCountry = "US",

                    // The primary language that the customer uses. This language will be the
                    // default language for ad groups in the customer’s campaigns.
                    MarketLanguage = LanguageType.English,

                    // The name of the customer. This element can contain a maximum of 100 characters.
                    Name = "Child Customer " + DateTime.UtcNow,
                };

                var account = new AdvertiserAccount
                {
                    // The location where your business is legally registered.
                    // The business address is used to determine your tax requirements.
                    BusinessAddress = new Address
                    {
                        BusinessName    = "Contoso",
                        City            = "Redmond",
                        Line1           = "One Microsoft Way",
                        CountryCode     = "US",
                        PostalCode      = "98052",
                        StateOrProvince = "WA",
                    },

                    // The type of currency that is used to settle the account. The service uses the currency information for billing purposes.
                    CurrencyCode = CurrencyCode.USD,

                    // Optionally you can set up each account with auto tagging.
                    // The AutoTagType is an account level setting that determines whether to append or replace
                    // the supported UTM tracking codes within the final URL of ads delivered. The default value is 'Inactive', and
                    // Bing Ads will not append any UTM tracking codes to your ad or keyword final URL.
                    AutoTagType = AutoTagType.Inactive,

                    // The name of the account. The name can contain a maximum of 100 characters and must be unique within the customer.
                    Name = "Child Account " + DateTime.UtcNow,

                    // The identifier of the customer that owns the account. In the Bing Ads API operations
                    // that require a customer identifier, this is the identifier that you set the CustomerId SOAP header to.
                    ParentCustomerId = (long)user.CustomerId,

                    // The list of key and value strings for tax information.
                    // The TaxId (VAT identifier) is optional. If specified, The VAT identifier must be valid
                    // in the country that you specified in the BusinessAddress element. Without a VAT registration
                    // number or exemption certificate, taxes might apply based on your business location.
                    TaxInformation = null,

                    // The time-zone value to use for campaigns in this account.
                    TimeZone = TimeZoneType.PacificTimeUSCanadaTijuana,
                };

                // Signup a new customer and account for the reseller.
                var signupCustomerResponse = await CustomerManagementExampleHelper.SignupCustomerAsync(
                    customer,
                    account,
                    user.CustomerId);

                OutputStatusMessage(string.Format("New Customer and Account:\n"));

                // This is the identifier that you will use to set the CustomerId
                // element in most of the Bing Ads API service operations.
                OutputStatusMessage(string.Format("\tCustomerId: {0}", signupCustomerResponse.CustomerId));

                // The read-only system-generated customer number that is used in the Bing Ads web application.
                // The customer number is of the form, Cnnnnnnn, where nnnnnnn is a series of digits.
                OutputStatusMessage(string.Format("\tCustomerNumber: {0}", signupCustomerResponse.CustomerNumber));

                // This is the identifier that you will use to set the AccountId and CustomerAccountId
                // elements in most of the Bing Ads API service operations.
                OutputStatusMessage(string.Format("\tAccountId: {0}", signupCustomerResponse.AccountId));

                // The read-only system generated account number that is used to identify the account in the Bing Ads web application.
                // The account number has the form xxxxxxxx, where xxxxxxxx is a series of any eight alphanumeric characters.
                OutputStatusMessage(string.Format("\tAccountNumber: {0}", signupCustomerResponse.AccountNumber));
            }
            // Catch authentication exceptions
            catch (OAuthTokenRequestException ex)
            {
                OutputStatusMessage(string.Format("Couldn't get OAuth tokens. Error: {0}. Description: {1}", ex.Details.Error, ex.Details.Description));
            }
            // Catch Customer Management service exceptions
            catch (FaultException <Microsoft.BingAds.V12.CustomerManagement.AdApiFaultDetail> ex)
            {
                OutputStatusMessage(string.Join("; ", ex.Detail.Errors.Select(error => string.Format("{0}: {1}", error.Code, error.Message))));
            }
            catch (FaultException <Microsoft.BingAds.V12.CustomerManagement.ApiFault> ex)
            {
                OutputStatusMessage(string.Join("; ", ex.Detail.OperationErrors.Select(error => string.Format("{0}: {1}", error.Code, error.Message))));
            }
            catch (Exception ex)
            {
                OutputStatusMessage(ex.Message);
            }
        }
コード例 #8
0
        public async override Task RunAsync(AuthorizationData authorizationData)
        {
            try
            {
                Service = new ServiceClient <ICustomerManagementService>(authorizationData);

                var getUserResponse = await GetUserAsync(null);

                var user = getUserResponse.User;

                // Only a user with the aggregator role (33) can sign up new customers.
                // If the user does not have the aggregator role, then do not continue.
                if (!getUserResponse.Roles.Contains(33))
                {
                    OutputStatusMessage("Only a user with the aggregator role (33) can sign up new customers.");
                    return;
                }

                // For Customer.CustomerAddress and Account.BusinessAddress, you can use the same address
                // as your aggregator user, although you must set Id and TimeStamp to null.
                var userAddress = user.ContactInfo.Address;
                userAddress.Id        = null;
                userAddress.TimeStamp = null;

                var customer = new Customer
                {
                    // The customer's business address.
                    CustomerAddress = userAddress,

                    // The list of key and value strings for forward compatibility. This element can be used
                    // to avoid otherwise breaking changes when new elements are added in future releases.
                    // There are currently no forward compatibility changes for the Customer object.
                    ForwardCompatibilityMap = null,

                    // The primary business segment of the customer, for example, automotive, food, or entertainment.
                    Industry = Industry.Other,

                    // The primary country where the customer operates. This country will be the
                    // default country for ad groups in the customer’s campaigns.
                    MarketCountry = "US",

                    // The primary language that the customer uses. This language will be the
                    // default language for ad groups in the customer’s campaigns.
                    MarketLanguage = LanguageType.English,

                    // The name of the customer. This element can contain a maximum of 100 characters.
                    Name = "Child Customer " + DateTime.UtcNow,
                };

                // Optionally you can set up each account with auto tagging.
                // The AutoTag key and value pair is an account level setting that determines whether to append or replace
                // the supported UTM tracking codes within the final URL of ads delivered. The default value is '0', and
                // Bing Ads will not append any UTM tracking codes to your ad or keyword final URL.
                var accountFCM = new List <KeyValuePair <string, string> >();
                accountFCM.Add(new KeyValuePair <string, string>(
                                   "AutoTag",
                                   "0"));

                var account = new AdvertiserAccount
                {
                    // The type of account. Bing Ads API only supports the Advertiser account.
                    AccountType = AccountType.Advertiser,

                    // The location where your business is legally registered.
                    // The business address is used to determine your tax requirements.
                    // BusinessAddress will be required in a future version of the Bing Ads API.
                    // Please start using it.
                    BusinessAddress = userAddress,

                    // The type of currency that is used to settle the account. The service uses the currency information for billing purposes.
                    CurrencyType = CurrencyType.USDollar,

                    // The list of key and value strings for forward compatibility. This element can be used
                    // to avoid otherwise breaking changes when new elements are added in future releases.
                    ForwardCompatibilityMap = accountFCM,

                    // The name of the account. The name can contain a maximum of 100 characters and must be unique within the customer.
                    Name = "Child Account " + DateTime.UtcNow,

                    // The identifier of the customer that owns the account. In the Bing Ads API operations
                    // that require a customer identifier, this is the identifier that you set the CustomerId SOAP header to.
                    ParentCustomerId = (long)user.CustomerId,

                    // The TaxId (VAT identifier) is optional. If specified, The VAT identifier must be valid
                    // in the country that you specified in the BusinessAddress element. Without a VAT registration
                    // number or exemption certificate, taxes might apply based on your business location.
                    TaxId = null,

                    // The default time-zone value to use for campaigns in this account.
                    // If not specified, the time zone will be set to PacificTimeUSCanadaTijuana by default.
                    // TimeZone will be required in a future version of the Bing Ads API.
                    // Please start using it.
                    TimeZone = TimeZoneType.PacificTimeUSCanadaTijuana,
                };

                // Signup a new customer and account for the reseller.
                var signupCustomerResponse = await SignupCustomerAsync(
                    customer,
                    account,
                    user.CustomerId);

                OutputStatusMessage(string.Format("New Customer and Account:\n"));

                // This is the identifier that you will use to set the CustomerId
                // element in most of the Bing Ads API service operations.
                OutputStatusMessage(string.Format("\tCustomerId: {0}", signupCustomerResponse.CustomerId));

                // The read-only system-generated customer number that is used in the Bing Ads web application.
                // The customer number is of the form, Cnnnnnnn, where nnnnnnn is a series of digits.
                OutputStatusMessage(string.Format("\tCustomerNumber: {0}", signupCustomerResponse.CustomerNumber));

                // This is the identifier that you will use to set the AccountId and CustomerAccountId
                // elements in most of the Bing Ads API service operations.
                OutputStatusMessage(string.Format("\tAccountId: {0}", signupCustomerResponse.AccountId));

                // The read-only system generated account number that is used to identify the account in the Bing Ads web application.
                // The account number has the form xxxxxxxx, where xxxxxxxx is a series of any eight alphanumeric characters.
                OutputStatusMessage(string.Format("\tAccountNumber: {0}", signupCustomerResponse.AccountNumber));
            }
            // Catch authentication exceptions
            catch (OAuthTokenRequestException ex)
            {
                OutputStatusMessage(string.Format("Couldn't get OAuth tokens. Error: {0}. Description: {1}", ex.Details.Error, ex.Details.Description));
            }
            // Catch Customer Management service exceptions
            catch (FaultException <Microsoft.BingAds.CustomerManagement.AdApiFaultDetail> ex)
            {
                OutputStatusMessage(string.Join("; ", ex.Detail.Errors.Select(error => string.Format("{0}: {1}", error.Code, error.Message))));
            }
            catch (FaultException <Microsoft.BingAds.CustomerManagement.ApiFault> ex)
            {
                OutputStatusMessage(string.Join("; ", ex.Detail.OperationErrors.Select(error => string.Format("{0}: {1}", error.Code, error.Message))));
            }
            catch (Exception ex)
            {
                OutputStatusMessage(ex.Message);
            }
        }
コード例 #9
0
 public AddPrepayAccountResponse TryAddPrepayAccount(ApiAuthentication auth, AdvertiserAccount prePayAccount)
 {
     return(MethodHelper.TryGet(AddPrepayAccount, this, auth, prePayAccount));
 }
コード例 #10
0
        public async Task <AddAccountResponse> AddAccountAsync(ApiAuthentication auth, AdvertiserAccount account)
        {
            var request = new AddAccountRequest
            {
                Account = account,
            };

            try
            {
                SetAuthHelper.SetAuth(auth, request);

                return(await Check().AddAccountAsync(request));
            }
            catch (Exception ex)
            {
                Log(new LogEventArgs(ServiceType.CustomerManagement, "AddAccountAsync", ex.Message, new { Request = request }, ex));
            }

            return(null);
        }