/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { using (ConstantDataService constantDataService = (ConstantDataService)user.GetService(AdWordsService.v201802.ConstantDataService)) { try { // Get all carriers. Carrier[] carriers = constantDataService.getCarrierCriterion(); // Display the results. if (carriers != null) { foreach (Carrier carrier in carriers) { Console.WriteLine( "Carrier name is '{0}', ID is {1} and country code is '{2}'.", carrier.name, carrier.id, carrier.countryCode); } } else { Console.WriteLine("No carriers were retrieved."); } // Get all languages. Language[] languages = constantDataService.getLanguageCriterion(); // Display the results. if (languages != null) { foreach (Language language in languages) { Console.WriteLine( "Language name is '{0}', ID is {1} and code is '{2}'.", language.name, language.id, language.code); } } else { Console.WriteLine("No languages were found."); } } catch (Exception e) { throw new System.ApplicationException( "Failed to get targetable carriers and languages.", e); } } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { using (ConstantDataService constantDataService = (ConstantDataService)user.GetService( AdWordsService.v201710.ConstantDataService)) { Selector selector = new Selector() { predicates = new Predicate[] { Predicate.In(ProductBiddingCategoryData.Fields.Country, new string[] { "US" }) } }; try { ProductBiddingCategoryData[] results = constantDataService.getProductBiddingCategoryData(selector); Dictionary <long, ProductCategory> biddingCategories = new Dictionary <long, ProductCategory>(); List <ProductCategory> rootCategories = new List <ProductCategory>(); foreach (ProductBiddingCategoryData productBiddingCategory in results) { long id = productBiddingCategory.dimensionValue.value; long parentId = 0; string name = productBiddingCategory.displayValue[0].value; if (productBiddingCategory.parentDimensionValue != null) { parentId = productBiddingCategory.parentDimensionValue.value; } if (!biddingCategories.ContainsKey(id)) { biddingCategories.Add(id, new ProductCategory()); } ProductCategory category = biddingCategories[id]; if (parentId != 0) { if (!biddingCategories.ContainsKey(parentId)) { biddingCategories.Add(parentId, new ProductCategory()); } ProductCategory parent = biddingCategories[parentId]; parent.Children.Add(category); } else { rootCategories.Add(category); } category.Id = id; category.Name = name; } DisplayProductCategories(rootCategories, ""); } catch (Exception e) { throw new System.ApplicationException("Failed to set shopping product category.", e); } } }
private void GetAgSettings2_Click(object sender, EventArgs e) { Dictionary <string, string> headers = new Dictionary <string, string>() { { "DeveloperToken", this.DeveloperToken.Text }, { "UserAgent", String.Format("Edge File Manager (version {0})", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()) }, { "EnableGzipCompression", this.EnableGzipCompression.Text }, { "ClientCustomerId", this.ClientCustomerId.Text }, { "Email", this.Email.Text } }; User = new AdWordsUser(headers); try { //Getting AuthToken (User.Config as AdWordsAppConfig).AuthToken = AdwordsUtill.GetAuthToken(User); } catch (Exception exc) { this.rchtxt.Text = exc.Message + " #### " + exc.InnerException != null ? exc.InnerException.Message : string.Empty; } AdGroupService agService = (AdGroupService)User.GetService(AdWordsService.v201302.AdGroupService); ConstantDataService constData = (ConstantDataService)User.GetService(AdWordsService.v201302.ConstantDataService); Language[] lang = constData.getLanguageCriterion(); // Create the selector. Selector selector = new Selector(); selector.fields = new string[] { "Id", "Status", "Clicks" }; // Set the filters. // Predicate predicate = new Predicate(); // predicate.field = "CampaignId"; // predicate.@operator = PredicateOperator.EQUALS; // predicate.values = new string[] { campaignId.ToString() }; // selector.predicates = new Predicate[] { predicate }; // Set the selector paging. selector.paging = new Paging(); int offset = 0; int pageSize = 500; AdGroupPage page = new AdGroupPage(); try { do { selector.paging.startIndex = offset; selector.paging.numberResults = pageSize; // Get all campaign targets. page = agService.get(selector); // Display the results. if (page != null && page.entries != null) { int i = offset; foreach (AdGroup adGroup in page.entries) { i++; } } offset += pageSize; } while (offset < page.totalNumEntries); Console.WriteLine("Number of ad groups criteria found: {0}", page.totalNumEntries); } catch (Exception ex) { throw new System.ApplicationException("Failed to get adgroup targeting criteria.", ex); } }