/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the MediaService. MediaService mediaService = (MediaService) user.GetService( AdWordsService.v201306.MediaService); // Create a selector. Selector selector = new Selector(); selector.fields = new string[] {"MediaId", "Width", "Height", "MimeType"}; // Set the filter. Predicate predicate = new Predicate(); predicate.@operator = PredicateOperator.IN; predicate.field = "Type"; predicate.values = new string[] {MediaMediaType.VIDEO.ToString(), MediaMediaType.IMAGE.ToString()}; selector.predicates = new Predicate[] {predicate}; // Set selector paging. selector.paging = new Paging(); int offset = 0; int pageSize = 500; MediaPage page = new MediaPage(); try { do { selector.paging.startIndex = offset; selector.paging.numberResults = pageSize; page = mediaService.get(selector); if (page != null && page.entries != null) { int i = offset; foreach (Media media in page.entries) { if (media is Video) { Video video = (Video) media; Console.WriteLine("{0}) Video with id \"{1}\" and name \"{2}\" was found.", i, video.mediaId, video.name); } else if (media is Image) { Image image = (Image) media; Dictionary<MediaSize, Dimensions> dimensions = CreateMediaDimensionMap(image.dimensions); Console.WriteLine("{0}) Image with id '{1}', dimensions '{2}x{3}', and MIME type " + "'{4}' was found.", i, image.mediaId, dimensions[MediaSize.FULL].width, dimensions[MediaSize.FULL].height, image.mimeType); } i++; } } offset += pageSize; } while (offset < page.totalNumEntries); Console.WriteLine("Number of images and videos found: {0}", page.totalNumEntries); } catch (Exception ex) { throw new System.ApplicationException("Failed to get images and videos.", ex); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the ManagedCustomerService. ManagedCustomerService managedCustomerService = (ManagedCustomerService) user.GetService( AdWordsService.v201306.ManagedCustomerService); managedCustomerService.RequestHeader.clientCustomerId = null; // Create selector. Selector selector = new Selector(); selector.fields = new String[] {"Login", "CustomerId", "Name"}; try { // Get results. ManagedCustomerPage page = managedCustomerService.get(selector); // Display serviced account graph. if (page.entries != null) { // Create map from customerId to customer node. Dictionary<long, ManagedCustomerTreeNode> customerIdToCustomerNode = new Dictionary<long, ManagedCustomerTreeNode>(); // Create account tree nodes for each customer. foreach (ManagedCustomer customer in page.entries) { ManagedCustomerTreeNode node = new ManagedCustomerTreeNode(); node.Account = customer; customerIdToCustomerNode.Add(customer.customerId, node); } // For each link, connect nodes in tree. if (page.links != null) { foreach (ManagedCustomerLink link in page.links) { ManagedCustomerTreeNode managerNode = customerIdToCustomerNode[link.managerCustomerId]; ManagedCustomerTreeNode childNode = customerIdToCustomerNode[link.clientCustomerId]; childNode.ParentNode = managerNode; if (managerNode != null) { managerNode.ChildAccounts.Add(childNode); } } } // Find the root account node in the tree. ManagedCustomerTreeNode rootNode = null; foreach (ManagedCustomer account in page.entries) { if (customerIdToCustomerNode[account.customerId].ParentNode == null) { rootNode = customerIdToCustomerNode[account.customerId]; break; } } // Display account tree. Console.WriteLine("Login, CustomerId, Name"); Console.WriteLine(rootNode.ToTreeString(0, new StringBuilder())); } else { Console.WriteLine("No serviced accounts were found."); } } catch (Exception ex) { throw new System.ApplicationException("Failed to create ad groups.", ex); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">Id of the campaign for which disapproved ads /// are retrieved.</param> public void Run(AdWordsUser user, long campaignId) { // Get the AdGroupAdService. AdGroupAdService service = (AdGroupAdService) user.GetService(AdWordsService.v201306.AdGroupAdService); // Create the selector. Selector selector = new Selector(); selector.fields = new string[] {"Id", "AdGroupCreativeApprovalStatus", "DisapprovalReasons"}; // Create the filter. Predicate campaignPredicate = new Predicate(); campaignPredicate.@operator = PredicateOperator.EQUALS; campaignPredicate.field = "CampaignId"; campaignPredicate.values = new string[] {campaignId.ToString()}; Predicate approvalPredicate = new Predicate(); approvalPredicate.@operator = PredicateOperator.EQUALS; approvalPredicate.field = "AdGroupCreativeApprovalStatus"; approvalPredicate.values = new string[] {AdGroupAdApprovalStatus.DISAPPROVED.ToString()}; selector.predicates = new Predicate[] {campaignPredicate, approvalPredicate}; // Set the selector paging. selector.paging = new Paging(); int offset = 0; int pageSize = 500; AdGroupAdPage page = new AdGroupAdPage(); try { do { selector.paging.startIndex = offset; selector.paging.numberResults = pageSize; // Get the disapproved ads. page = service.get(selector); // Display the results. if (page != null && page.entries != null) { int i = offset; foreach (AdGroupAd adGroupAd in page.entries) { Console.WriteLine("{0}) Ad id {1} has been disapproved for the following " + "reason(s):", i, adGroupAd.ad.id); foreach (string reason in adGroupAd.ad.disapprovalReasons) { Console.WriteLine(" {0}", reason); } i++; } } offset += pageSize; } while (offset < page.totalNumEntries); Console.WriteLine("Number of disapproved ads found: {0}", page.totalNumEntries); } catch (Exception ex) { throw new System.ApplicationException("Failed to get disapproved ads.", ex); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the CampaignService. CampaignService campaignService = (CampaignService) user.GetService(AdWordsService.v201306.CampaignService); // Create the selector. Selector selector = new Selector(); selector.fields = new string[] {"Id", "Name", "Status", "Impressions", "Cost", "Ctr"}; // Create the predicates. Predicate predicate = new Predicate(); predicate.field = "Impressions"; predicate.@operator = PredicateOperator.GREATER_THAN; predicate.values = new string[] {"0"}; selector.predicates = new Predicate[] {predicate}; // Set the date range. DateRange dateRange = new DateRange(); dateRange.min = DateTime.Now.AddDays(-8).ToString("yyyyMMdd"); dateRange.max = DateTime.Now.AddDays(-1).ToString("yyyyMMdd"); selector.dateRange = dateRange; // Set the selector paging. selector.paging = new Paging(); int offset = 0; int pageSize = 500; CampaignPage page = new CampaignPage(); try { do { selector.paging.startIndex = offset; selector.paging.numberResults = pageSize; // Get the campaigns. page = campaignService.get(selector); // Display the results. if (page != null && page.entries != null) { int i = offset; foreach (Campaign campaign in page.entries) { Console.WriteLine("{0}) Campaign with id = '{1}', name = '{2}' had the following " + "stats last week", i + 1, campaign.id, campaign.name); Console.WriteLine(" Clicks: {0}, Impressions: {1}, Cost: {2} micros. Ctr: {3}", campaign.campaignStats.clicks, campaign.campaignStats.impressions, campaign.campaignStats.cost,campaign.campaignStats.ctr); i++; } } offset += pageSize; } while (offset < page.totalNumEntries); Console.WriteLine("Number of matching campaigns found: {0}", page.totalNumEntries); } catch (Exception ex) { throw new System.ApplicationException("Failed to retrieve matching campaigns", ex); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="fileName">The file to which the report is downloaded. /// </param> public void Run(AdWordsUser user, string fileName) { ReportDefinition definition = new ReportDefinition(); definition.reportName = "Last 7 days CRITERIA_PERFORMANCE_REPORT"; definition.reportType = ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT; definition.downloadFormat = DownloadFormat.GZIPPED_CSV; definition.dateRangeType = ReportDefinitionDateRangeType.LAST_7_DAYS; // Create selector. Selector selector = new Selector(); selector.fields = new string[] {"CampaignId", "AdGroupId", "Id", "CriteriaType", "Criteria", "CriteriaDestinationUrl", "Clicks", "Impressions", "Cost"}; Predicate predicate = new Predicate(); predicate.field = "Status"; predicate.@operator = PredicateOperator.IN; predicate.values = new string[] {"ACTIVE", "PAUSED"}; selector.predicates = new Predicate[] {predicate}; definition.selector = selector; definition.includeZeroImpressions = true; string filePath = ExampleUtilities.GetHomeDir() + Path.DirectorySeparatorChar + fileName; try { // If you know that your report is small enough to fit in memory, then // you can instead use // ReportUtilities utilities = new ReportUtilities(user); // utilities.ReportVersion = "v201306"; // ClientReport report = utilities.GetClientReport(definition); // // // Get the text report directly if you requested a text format // // (e.g. xml) // string reportText = report.Text; // // // Get the binary report if you requested a binary format // // (e.g. gzip) // byte[] reportBytes = report.Contents; // // // Deflate a zipped binary report for further processing. // string deflatedReportText = Encoding.UTF8.GetString( // MediaUtilities.DeflateGZipData(report.Contents)); ReportUtilities utilities = new ReportUtilities(user); utilities.ReportVersion = "v201306"; utilities.DownloadClientReport(definition, filePath); Console.WriteLine("Report was downloaded to '{0}'.", filePath); } catch (Exception ex) { throw new System.ApplicationException("Failed to download report.", ex); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">Id of the campaign for which ad groups are /// retrieved.</param> public void Run(AdWordsUser user, long campaignId) { // Get the AdGroupService. AdGroupService adGroupService = (AdGroupService) user.GetService(AdWordsService.v201306.AdGroupService); // Create the selector. Selector selector = new Selector(); selector.fields = new string[] {"Id", "Name"}; // Create 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 the ad groups. page = adGroupService.get(selector); // Display the results. if (page != null && page.entries != null) { int i = offset; foreach (AdGroup adGroup in page.entries) { Console.WriteLine("{0}) Ad group name is '{1}' and id is {2}.", i + 1, adGroup.name, adGroup.id); i++; } } offset += pageSize; } while (offset < page.totalNumEntries); Console.WriteLine("Number of ad groups found: {0}", page.totalNumEntries); } catch (Exception ex) { throw new System.ApplicationException("Failed to retrieve ad groups.", ex); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the CampaignService. CampaignService campaignService = (CampaignService) user.GetService(AdWordsService.v201306.CampaignService); // Create the selector. Selector selector = new Selector(); selector.fields = new string[] {"Id", "Name", "Status"}; // Set the selector paging. selector.paging = new Paging(); int offset = 0; int pageSize = 500; CampaignPage page = new CampaignPage(); try { do { selector.paging.startIndex = offset; selector.paging.numberResults = pageSize; // Get the campaigns. page = campaignService.get(selector); // Display the results. if (page != null && page.entries != null) { int i = offset; foreach (Campaign campaign in page.entries) { Console.WriteLine("{0}) Campaign with id = '{1}', name = '{2}' and status = '{3}'" + " was found.", i + 1, campaign.id, campaign.name, campaign.status); i++; } } offset += pageSize; } while (offset < page.totalNumEntries); Console.WriteLine("Number of campaigns found: {0}", page.totalNumEntries); } catch (Exception ex) { throw new System.ApplicationException("Failed to retrieve campaigns", ex); } }
/// <summary> /// Runs the specified user. /// </summary> /// <param name="user">The user.</param> /// <param name="adGroupId">Id of the ad group for which bid simulations are /// retrieved.</param> public void Run(AdWordsUser user, long adGroupId) { // Get the DataService. DataService dataService = (DataService) user.GetService(AdWordsService.v201306.DataService); // Create the selector. Selector selector = new Selector(); selector.fields = new string[] {"AdGroupId", "LandscapeType", "LandscapeCurrent", "StartDate", "EndDate", "Bid", "LocalClicks", "LocalCost", "MarginalCpc", "LocalImpressions"}; // Set the filters. Predicate adGroupPredicate = new Predicate(); adGroupPredicate.field = "AdGroupId"; adGroupPredicate.@operator = PredicateOperator.IN; adGroupPredicate.values = new string[] {adGroupId.ToString()}; selector.predicates = new Predicate[] {adGroupPredicate}; try { // Get bid landscape for ad group. AdGroupBidLandscapePage page = dataService.getAdGroupBidLandscape(selector); if (page != null && page.entries != null && page.entries.Length > 0) { foreach (AdGroupBidLandscape bidLandscape in page.entries) { Console.WriteLine("Found ad group bid landscape with ad group id '{0}', type '{1}', " + "current: '{2}', start date '{3}', end date '{4}', and landscape points", bidLandscape.adGroupId, bidLandscape.type, bidLandscape.landscapeCurrent, bidLandscape.startDate, bidLandscape.endDate); foreach (BidLandscapeLandscapePoint point in bidLandscape.landscapePoints) { Console.WriteLine("- bid: {0} => clicks: {1}, cost: {2}, marginalCpc: {3}, " + "impressions: {4}", point.bid.microAmount, point.bid.microAmount, point.clicks, point.cost.microAmount, point.marginalCpc.microAmount, point.impressions); } } } else { Console.WriteLine("No ad group bid landscapes were found."); } } catch (Exception ex) { throw new System.ApplicationException("Failed to get ad group bid landscapes.", ex); } }
public virtual BudgetOrderPage get(Selector serviceSelector) { object[] results = this.Invoke("get", new object[] { serviceSelector }); return ((BudgetOrderPage) (results[0])); }
public virtual CampaignCriterionPage get(Selector serviceSelector) { object[] results = this.Invoke("get", new object[] { serviceSelector }); return ((CampaignCriterionPage) (results[0])); }
public virtual BiddingStrategyPage get(Selector selector) { object[] results = this.Invoke("get", new object[] { selector }); return ((BiddingStrategyPage) (results[0])); }
/// <summary> /// Retrieve an existing feed that is mapped to hold sitelinks. The first /// active sitelinks feed is retrieved by this method. /// </summary> /// <param name="feedMappingService">The feed mapping service.</param> /// <returns>A SiteLinksFeed if a feed is found, or null otherwise.</returns> private static SiteLinksFeed getExistingFeed(FeedMappingService feedMappingService) { Selector selector = new Selector(); selector.fields = new string[] {"FeedId", "FeedMappingId", "PlaceholderType", "Status", "AttributeFieldMappings"}; Predicate placeHolderPredicate = new Predicate(); placeHolderPredicate.field = "PlaceholderType"; placeHolderPredicate.@operator = PredicateOperator.EQUALS; placeHolderPredicate.values = new string[] {PLACEHOLDER_SITELINKS.ToString()}; Predicate statusPredicate = new Predicate(); statusPredicate.field = "Status"; statusPredicate.@operator = PredicateOperator.EQUALS; statusPredicate.values = new string[] {"ACTIVE"}; selector.predicates = new Predicate[] {placeHolderPredicate, statusPredicate}; FeedMappingPage page = feedMappingService.get(selector); if (page != null && page.entries != null && page.entries.Length > 0) { foreach (FeedMapping feedMapping in page.entries) { long? feedId = feedMapping.feedId; long? textAttributeId = null; long? urlAttributeId = null; foreach (AttributeFieldMapping attributeMapping in feedMapping.attributeFieldMappings) { if (attributeMapping.fieldId == PLACEHOLDER_FIELD_SITELINK_LINK_TEXT) { textAttributeId = attributeMapping.feedAttributeId; } else if (attributeMapping.fieldId == PLACEHOLDER_FIELD_SITELINK_URL) { urlAttributeId = attributeMapping.feedAttributeId; } } if (feedId != null && textAttributeId != null && urlAttributeId != null) { SiteLinksFeed siteLinksFeed = new SiteLinksFeed(); siteLinksFeed.SiteLinksFeedId = feedId.Value; siteLinksFeed.LinkTextFeedAttributeId = textAttributeId.Value; siteLinksFeed.LinkUrlFeedAttributeId = urlAttributeId.Value; return siteLinksFeed; } } } return null; }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the LocationCriterionService. LocationCriterionService locationCriterionService = (LocationCriterionService) user.GetService(AdWordsService.v201306. LocationCriterionService); string[] locationNames = new string[] {"Paris", "Quebec", "Spain", "Deutschland"}; Selector selector = new Selector(); selector.fields = new string[] {"Id", "LocationName", "CanonicalName", "DisplayType", "ParentLocations", "Reach", "TargetingStatus"}; // Location names must match exactly, only EQUALS and IN are supported. Predicate predicate1 = new Predicate(); predicate1.field = "LocationName"; predicate1.@operator = PredicateOperator.IN; predicate1.values = locationNames; // Set the locale of the returned location names. Predicate predicate2 = new Predicate(); predicate2.field = "Locale"; predicate2.@operator = PredicateOperator.EQUALS; predicate2.values = new string[] {"en"}; selector.predicates = new Predicate[] {predicate1, predicate2}; try { // Make the get request. LocationCriterion[] locationCriteria = locationCriterionService.get(selector); // Display the resulting location criteria. foreach (LocationCriterion locationCriterion in locationCriteria) { string parentLocations = ""; if (locationCriterion.location != null && locationCriterion.location.parentLocations != null) { foreach (Location location in locationCriterion.location.parentLocations) { parentLocations += GetLocationString(location) + ", "; } parentLocations.TrimEnd(',', ' '); } else { parentLocations = "N/A"; } Console.WriteLine("The search term '{0}' returned the location '{1}' of type '{2}' " + "with parent locations '{3}', reach '{4}' and targeting status '{5}.", locationCriterion.searchTerm, locationCriterion.location.locationName, locationCriterion.location.displayType, parentLocations, locationCriterion.reach, locationCriterion.location.targetingStatus); } } catch (Exception ex) { throw new System.ApplicationException("Failed to get location criteria.", ex); } }
public virtual AdGroupBidLandscapePage getAdGroupBidLandscape(Selector serviceSelector) { object[] results = this.Invoke("getAdGroupBidLandscape", new object[] { serviceSelector }); return ((AdGroupBidLandscapePage) (results[0])); }
public virtual LocationCriterion[] get(Selector selector) { object[] results = this.Invoke("get", new object[] { selector }); return ((LocationCriterion[]) (results[0])); }
public virtual FeedMappingPage get(Selector selector) { object[] results = this.Invoke("get", new object[] { selector }); return ((FeedMappingPage) (results[0])); }
public virtual ExperimentPage get(Selector serviceSelector) { object[] results = this.Invoke("get", new object[] { serviceSelector }); return ((ExperimentPage) (results[0])); }
/// <summary> /// Gets all campaign ids in the account. /// </summary> /// <param name="user">The user for which campaigns are retrieved.</param> /// <returns>The list of campaign ids.</returns> private long[] GetAllCampaignIds(AdWordsUser user) { // Get the CampaignService. CampaignService campaignService = (CampaignService) user.GetService(AdWordsService.v201306.CampaignService); List<long> allCampaigns = new List<long>(); // Create the selector. Selector selector = new Selector(); selector.fields = new string[] {"Id"}; // Get all campaigns. CampaignPage page = campaignService.get(selector); // Return the results. if (page != null && page.entries != null) { foreach (Campaign campaign in page.entries) { allCampaigns.Add(campaign.id); } } return allCampaigns.ToArray(); }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the AdGroupCriterionService. AdGroupCriterionService adGroupCriterionService = (AdGroupCriterionService) user.GetService(AdWordsService.v201306.AdGroupCriterionService); // Create a selector. Selector selector = new Selector(); selector.fields = new string[] {"Id", "AdGroupId", "KeywordText"}; // Select only keywords. Predicate predicate = new Predicate(); predicate.field = "CriteriaType"; predicate.@operator = PredicateOperator.EQUALS; predicate.values = new string[] {"KEYWORD"}; selector.predicates = new Predicate[] {predicate}; // Set the selector paging. selector.paging = new Paging(); int offset = 0; int pageSize = 500; AdGroupCriterionPage page = new AdGroupCriterionPage(); try { do { selector.paging.startIndex = offset; selector.paging.numberResults = pageSize; // Get the keywords. page = adGroupCriterionService.get(selector); // Display the results. if (page != null && page.entries != null) { int i = offset; foreach (AdGroupCriterion adGroupCriterion in page.entries) { bool isNegative = (adGroupCriterion is NegativeAdGroupCriterion); // If you are retrieving multiple type of criteria, then you may // need to check for // // if (adGroupCriterion is Keyword) { ... } // // to identify the criterion type. Keyword keyword = (Keyword) adGroupCriterion.criterion; if (isNegative) { Console.WriteLine("{0}) Negative keyword with ad group ID = '{1}', keyword ID " + "= '{2}', and text = '{3}' was found.", i + 1, adGroupCriterion.adGroupId, keyword.id, keyword.text); } else { Console.WriteLine("{0}) Keyword with ad group ID = '{1}', keyword ID = '{2}', " + "text = '{3}' and matchType = '{4} was found.", i + 1, adGroupCriterion.adGroupId, keyword.id, keyword.text, keyword.matchType); } i++; } } offset += pageSize; } while (offset < page.totalNumEntries); Console.WriteLine("Number of keywords found: {0}", page.totalNumEntries); } catch (Exception ex) { throw new System.ApplicationException("Failed to retrieve keywords.", ex); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="adGroupId">Id of the ad group for which keyword bid /// simulations are retrieved.</param> /// <param name="keywordId">Id of the keyword for which bid simulations are /// retrieved.</param> public void Run(AdWordsUser user, long adGroupId, long keywordId) { // Get the DataService. DataService dataService = (DataService) user.GetService(AdWordsService.v201306.DataService); // Create the selector. Selector selector = new Selector(); selector.fields = new string[] {"AdGroupId", "CriterionId", "StartDate", "EndDate", "Bid", "LocalClicks", "LocalCost", "MarginalCpc", "LocalImpressions"}; // Create the filters. Predicate adGroupPredicate = new Predicate(); adGroupPredicate.field = "AdGroupId"; adGroupPredicate.@operator = PredicateOperator.IN; adGroupPredicate.values = new string[] {adGroupId.ToString()}; Predicate keywordPredicate = new Predicate(); keywordPredicate.field = "CriterionId"; keywordPredicate.@operator = PredicateOperator.IN; keywordPredicate.values = new string[] {keywordId.ToString()}; selector.predicates = new Predicate[] {adGroupPredicate, keywordPredicate}; // Set selector paging. selector.paging = new Paging(); int offset = 0; int pageSize = 500; CriterionBidLandscapePage page = new CriterionBidLandscapePage(); try { do { selector.paging.startIndex = offset; selector.paging.numberResults = pageSize; // Get bid landscape for keywords. page = dataService.getCriterionBidLandscape(selector); // Display bid landscapes. if (page != null && page.entries != null) { int i = offset; foreach (CriterionBidLandscape bidLandscape in page.entries) { Console.WriteLine("{0}) Found criterion bid landscape with ad group id '{1}', " + "keyword id '{2}', start date '{3}', end date '{4}', and landscape points:", i, bidLandscape.adGroupId, bidLandscape.criterionId, bidLandscape.startDate, bidLandscape.endDate); foreach (BidLandscapeLandscapePoint bidLandscapePoint in bidLandscape.landscapePoints) { Console.WriteLine("- bid: {0} => clicks: {1}, cost: {2}, marginalCpc: {3}, " + "impressions: {4}\n", bidLandscapePoint.bid.microAmount, bidLandscapePoint.clicks, bidLandscapePoint.cost.microAmount, bidLandscapePoint.marginalCpc.microAmount, bidLandscapePoint.impressions); } i++; } } offset += pageSize; } while (offset < page.totalNumEntries); Console.WriteLine("Number of keyword bid landscapes found: {0}", page.totalNumEntries); } catch (Exception ex) { throw new System.ApplicationException("Failed to retrieve keyword bid landscapes.", ex); } }
public virtual CampaignSharedSetPage get(Selector selector) { object[] results = this.Invoke("get", new object[] { selector }); return ((CampaignSharedSetPage) (results[0])); }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">Id of the campaign from which targeting /// criteria are retrieved.</param> public void Run(AdWordsUser user, long campaignId) { // Get the CampaignCriterionService. CampaignCriterionService campaignCriterionService = (CampaignCriterionService) user.GetService( AdWordsService.v201306.CampaignCriterionService); // Create the selector. Selector selector = new Selector(); selector.fields = new string[] {"Id", "CriteriaType", "CampaignId"}; // 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; CampaignCriterionPage page = new CampaignCriterionPage(); try { do { selector.paging.startIndex = offset; selector.paging.numberResults = pageSize; // Get all campaign targets. page = campaignCriterionService.get(selector); // Display the results. if (page != null && page.entries != null) { int i = offset; foreach (CampaignCriterion campaignCriterion in page.entries) { string negative = (campaignCriterion is NegativeCampaignCriterion) ? "Negative " : ""; Console.WriteLine("{0}) {1}Campaign criterion with id = '{2}' and Type = {3} was " + " found for campaign id '{4}'", i, negative, campaignCriterion.criterion.id, campaignCriterion.criterion.type, campaignCriterion.campaignId); i++; } } offset += pageSize; } while (offset < page.totalNumEntries); Console.WriteLine("Number of campaign targeting criteria found: {0}", page.totalNumEntries); } catch (Exception ex) { throw new System.ApplicationException("Failed to get campaign targeting criteria.", ex); } }
public virtual ConversionTrackerPage get(Selector serviceSelector) { object[] results = this.Invoke("get", new object[] { serviceSelector }); return ((ConversionTrackerPage) (results[0])); }
public virtual SharedCriterionPage get(Selector selector) { object[] results = this.Invoke("get", new object[] { selector }); return ((SharedCriterionPage) (results[0])); }
public virtual CriterionBidLandscapePage getCriterionBidLandscape(Selector serviceSelector) { object[] results = this.Invoke("getCriterionBidLandscape", new object[] { serviceSelector }); return ((CriterionBidLandscapePage) (results[0])); }
public virtual AdGroupBidModifierPage get(Selector selector) { object[] results = this.Invoke("get", new object[] { selector }); return ((AdGroupBidModifierPage) (results[0])); }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="adGroupId">Id of the ad group from which text ads are /// retrieved.</param> public void Run(AdWordsUser user, long adGroupId) { // Get the AdGroupAdService. AdGroupAdService service = (AdGroupAdService) user.GetService(AdWordsService.v201306.AdGroupAdService); // Create a selector. Selector selector = new Selector(); selector.fields = new string[] {"Id", "Status", "Headline", "Description1", "Description2", "DisplayUrl"}; // Set the sort order. OrderBy orderBy = new OrderBy(); orderBy.field = "Id"; orderBy.sortOrder = SortOrder.ASCENDING; selector.ordering = new OrderBy[] {orderBy}; // Restrict the fetch to only the selected ad group id. Predicate adGroupPredicate = new Predicate(); adGroupPredicate.field = "AdGroupId"; adGroupPredicate.@operator = PredicateOperator.EQUALS; adGroupPredicate.values = new string[] {adGroupId.ToString()}; // Retrieve only text ads. Predicate typePredicate = new Predicate(); typePredicate.field = "AdType"; typePredicate.@operator = PredicateOperator.EQUALS; typePredicate.values = new string[] {"TEXT_AD"}; // By default disabled ads aren't returned by the selector. To return // them include the DISABLED status in the statuses field. Predicate statusPredicate = new Predicate(); statusPredicate.field = "Status"; statusPredicate.@operator = PredicateOperator.IN; statusPredicate.values = new string[] {AdGroupAdStatus.ENABLED.ToString(), AdGroupAdStatus.PAUSED.ToString(), AdGroupAdStatus.DISABLED.ToString()}; selector.predicates = new Predicate[] {adGroupPredicate, statusPredicate, typePredicate}; // Select the selector paging. selector.paging = new Paging(); int offset = 0; int pageSize = 500; AdGroupAdPage page = new AdGroupAdPage(); try { do { selector.paging.startIndex = offset; selector.paging.numberResults = pageSize; // Get the text ads. page = service.get(selector); // Display the results. if (page != null && page.entries != null) { int i = offset; foreach (AdGroupAd adGroupAd in page.entries) { TextAd textAd = (TextAd) adGroupAd.ad; Console.WriteLine("{0}) Ad id is {1} and status is {2}", i + 1, textAd.id, adGroupAd.status); Console.WriteLine(" {0}\n {1}\n {2}\n {3}", textAd.headline, textAd.description1, textAd.description2, textAd.displayUrl); i++; } } offset += pageSize; } while (offset < page.totalNumEntries); Console.WriteLine("Number of text ads found: {0}", page.totalNumEntries); } catch (Exception ex) { throw new System.ApplicationException("Failed to get text ads", ex); } }
public virtual AdParamPage get(Selector serviceSelector) { object[] results = this.Invoke("get", new object[] { serviceSelector }); return ((AdParamPage) (results[0])); }
public virtual ManagedCustomerPage get(Selector serviceSelector) { object[] results = this.Invoke("get", new object[] { serviceSelector }); return ((ManagedCustomerPage) (results[0])); }
/// <summary> /// Gets the legacy sitelinks for campaign. /// </summary> /// <param name="campaignExtensionService">The campaign extension service.</param> /// <param name="campaignId">The campaign id.</param> /// <returns>The CampaignAdExtension that contains the legacy sitelinks, or /// null if there are no legacy sitelinks in this campaign.</returns> private static CampaignAdExtension getLegacySitelinksForCampaign( CampaignAdExtensionService campaignExtensionService, long campaignId) { // Create the selector. Selector selector = new Selector(); selector.fields = new string[] {"CampaignId", "AdExtensionId", "Status", "DisplayText", "DestinationUrl"}; // Filter the results for specified campaign id. Predicate campaignPredicate = new Predicate(); campaignPredicate.@operator = PredicateOperator.EQUALS; campaignPredicate.field = "CampaignId"; campaignPredicate.values = new string[] {campaignId.ToString()}; // Filter the results for active campaign ad extensions. You may add // additional filtering conditions here as required. Predicate statusPredicate = new Predicate(); statusPredicate.@operator = PredicateOperator.EQUALS; statusPredicate.field = "Status"; statusPredicate.values = new string[] {CampaignAdExtensionStatus.ACTIVE.ToString()}; // Filter for sitelinks ad extension type. Predicate typePredicate = new Predicate(); typePredicate.@operator = PredicateOperator.EQUALS; typePredicate.field = "AdExtensionType"; typePredicate.values = new string[] {"SITELINKS_EXTENSION"}; selector.predicates = new Predicate[] {campaignPredicate, statusPredicate, typePredicate}; CampaignAdExtensionPage page = campaignExtensionService.get(selector); if (page.entries != null && page.entries.Length > 0) { return page.entries[0]; } else { return null; } }