/// <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.v201309.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.v201309.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.v201309.AdGroupAdService); // Create the selector. Selector selector = new Selector(); selector.fields = new string[] {"Id", "AdGroupCreativeApprovalStatus", "AdGroupAdDisapprovalReasons"}; // 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.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> /// The main method. /// </summary> /// <param name="args">Command line arguments.</param> static void Main(string[] args) { AdWordsUser user = new AdWordsUser(); AdWordsAppConfig config = (user.Config as AdWordsAppConfig); if (config.AuthorizationMethod == AdWordsAuthorizationMethod.OAuth2) { if (config.OAuth2Mode == OAuth2Flow.APPLICATION && string.IsNullOrEmpty(config.OAuth2RefreshToken)) { DoAuth2Authorization(user); } } else { throw new Exception("Authorization mode is not OAuth."); } Console.Write("Enter the customer id: "); string customerId = Console.ReadLine(); config.ClientCustomerId = customerId; // Get the CampaignService. CampaignService campaignService = (CampaignService) user.GetService(AdWordsService.v201309.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 code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the ExpressBusinessService. ExpressBusinessService businessService = (ExpressBusinessService) user.GetService(AdWordsService.v201309.ExpressBusinessService); Selector selector = new Selector(); selector.fields = new String[] { "Id", "Name", "Website", "Address", "GeoPoint", "Status" }; // To get all express businesses owned by the current customer, // simply skip the call to selector.setPredicates below. Predicate predicate = new Predicate(); predicate.field = "Status"; predicate.@operator = PredicateOperator.EQUALS; predicate.values = new string[] { "ACTIVE" }; selector.predicates = new Predicate[] { predicate }; // Set the selector paging. selector.paging = new Paging(); int offset = 0; int pageSize = 500; ExpressBusinessPage page = null; try { do { selector.paging.startIndex = offset; selector.paging.numberResults = pageSize; // Get all businesses. page = businessService.get(selector); // Display the results. if (page != null && page.entries != null) { int i = offset; foreach (ExpressBusiness business in page.entries) { Console.WriteLine("{0}) Express business found with name '{1}', id = {2}, " + "website = {3} and status = {4}.\n", i + 1, business.name, business.id, business.website, business.status); Console.WriteLine("Address"); Console.WriteLine("======="); Console.WriteLine(FormatAddress(business.address)); Console.WriteLine("Co-ordinates: {0}\n", FormatGeopoint(business.geoPoint)); i++; } } offset += pageSize; } while (offset < page.totalNumEntries); Console.WriteLine("Number of businesses found: {0}", page.totalNumEntries); } catch (Exception ex) { throw new System.ApplicationException("Failed to retrieve express business.", ex); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="productServiceSuggestion">The product/service suggestion. /// </param> /// <param name="localeText">The locale text.</param> public void Run(AdWordsUser user, string productServiceSuggestion, string localeText) { // Get the service, which loads the required classes. ProductServiceService productServiceService = (ProductServiceService) user.GetService( AdWordsService.v201309.ProductServiceService); // Create selector. Selector selector = new Selector(); selector.fields = new string[] {"ProductServiceText"}; // Create predicates. Predicate textPredicate = new Predicate(); textPredicate.field = "ProductServiceText"; textPredicate.@operator = PredicateOperator.EQUALS; textPredicate.values = new string[] {productServiceSuggestion}; Predicate localePredicate = new Predicate(); localePredicate.field = "Locale"; localePredicate.@operator = PredicateOperator.EQUALS; localePredicate.values = new string[]{localeText}; selector.predicates = new Predicate[] {textPredicate, localePredicate}; // Set the selector paging. selector.paging = new Paging(); int offset = 0; int pageSize = 500; ProductServicePage page = null; try { do { selector.paging.startIndex = offset; selector.paging.numberResults = pageSize; // Make the get request. page = productServiceService.get(selector); // Display the results. if (page != null && page.entries != null) { int i = offset; foreach (ProductService productService in page.entries) { Console.WriteLine("Product/service with text '{0}' found", productService.text); i++; } } offset += pageSize; } while (offset < page.totalNumEntries); Console.WriteLine("Number of products/services found: {0}", page.totalNumEntries); } catch (Exception ex) { throw new System.ApplicationException("Failed to retrieve products/services.", 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 = "v201309"; // 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 = "v201309"; 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.v201309.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> /// <param name="businessId">The AdWords Express business id.</param> public void Run(AdWordsUser user, long businessId) { // Get the PromotionService. PromotionService promotionService = (PromotionService) user.GetService(AdWordsService.v201309.PromotionService); // Set the business ID to the service. promotionService.RequestHeader.expressBusinessId = businessId; Selector selector = new Selector(); selector.fields = new String[] {"PromotionId", "Name", "Status", "DestinationUrl", "StreetAddressVisible", "CallTrackingEnabled", "ContentNetworkOptedOut", "Budget", "PromotionCriteria", "RemainingBudget", "Creatives", "CampaignIds" }; // Set the selector paging. selector.paging = new Paging(); int offset = 0; int pageSize = 500; PromotionPage page = null; try { do { selector.paging.startIndex = offset; selector.paging.numberResults = pageSize; // Get all promotions for the business. page = promotionService.get(selector); // Display the results. if (page != null && page.entries != null) { int i = offset; foreach (Promotion promotion in page.entries) { // Summary. Console.WriteLine("0) Express promotion with name = {1} and id = {2} was found.", i + 1, promotion.id, promotion.name); i++; } } offset += pageSize; } while (offset < page.totalNumEntries); Console.WriteLine("Number of promotions found: {0}", page.totalNumEntries); } catch (Exception ex) { throw new System.ApplicationException("Failed to retrieve promotions.", 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.v201309.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.v201309.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 CriterionBidLandscapePage getCriterionBidLandscape(Selector serviceSelector) { object[] results = this.Invoke("getCriterionBidLandscape", new object[] { serviceSelector }); return ((CriterionBidLandscapePage) (results[0])); }
public virtual ExperimentPage get(Selector serviceSelector) { object[] results = this.Invoke("get", new object[] { serviceSelector }); return ((ExperimentPage) (results[0])); }
/// <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.v201309.AdGroupCriterionService); // Create a selector. Selector selector = new Selector(); selector.fields = new string[] {"Id", "AdGroupId", "PlacementUrl"}; // Select only keywords. Predicate predicate = new Predicate(); predicate.field = "CriteriaType"; predicate.@operator = PredicateOperator.EQUALS; predicate.values = new string[] {"PLACEMENT"}; 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 Placement) { ... } // // to identify the criterion type. Placement placement = (Placement) adGroupCriterion.criterion; if (isNegative) { Console.WriteLine("{0}) Negative placement with ad group ID = '{1}', placement " + "ID = '{2}', and url = '{3}' was found.", i, adGroupCriterion.adGroupId, placement.id, placement.url); } else { Console.WriteLine("{0}) Placement with ad group ID = '{1}', placement ID = '{2}' " + "and url = '{3}' was found.", i, adGroupCriterion.adGroupId, placement.id, placement.url); } i++; } } offset += pageSize; } while (offset < page.totalNumEntries); Console.WriteLine("Number of placements found: {0}", page.totalNumEntries); } catch (Exception ex) { throw new System.ApplicationException("Failed to retrieve placements."); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="businessId">The AdWords Express business id.</param> public void Run(AdWordsUser user, long businessId) { // Get the ExpressBusinessService. ExpressBusinessService businessService = (ExpressBusinessService) user.GetService(AdWordsService.v201309.ExpressBusinessService); // Get the PromotionService PromotionService promotionService = (PromotionService) user.GetService(AdWordsService.v201309.PromotionService); // Get the business for the businessId. We will need its geo point to // create a Proximity criterion for the new Promotion. Selector businessSelector = new Selector(); Predicate predicate = new Predicate(); predicate.field = "Id"; predicate.@operator = PredicateOperator.EQUALS; predicate.values = new string[] { businessId.ToString() }; businessSelector.predicates = new Predicate[] { predicate }; businessSelector.fields = new string[] { "Id", "GeoPoint" }; ExpressBusinessPage businessPage = businessService.get(businessSelector); if (businessPage == null || businessPage.entries == null || businessPage.entries.Length == 0) { Console.WriteLine("No business was found."); return; } // Set the business ID to the service. promotionService.RequestHeader.expressBusinessId = businessId; // First promotion Promotion marsTourPromotion = new Promotion(); Money budget = new Money(); budget.microAmount = 1000000L; marsTourPromotion.name = "Mars Tour Promotion " + ExampleUtilities.GetShortRandomString(); marsTourPromotion.status = PromotionStatus.PAUSED; marsTourPromotion.destinationUrl = "http://www.example.com"; marsTourPromotion.budget = budget; marsTourPromotion.callTrackingEnabled = true; // Criteria // Criterion - Travel Agency product service ProductService productService = new ProductService(); productService.text = "Travel Agency"; // Criterion - English language // The ID can be found in the documentation: // https://developers.google.com/adwords/api/docs/appendix/languagecodes Language language = new Language(); language.id = 1000L; // Criterion - Within 15 miles Proximity proximity = new Proximity(); proximity.geoPoint = businessPage.entries[0].geoPoint; proximity.radiusDistanceUnits = ProximityDistanceUnits.MILES; proximity.radiusInUnits = 15; marsTourPromotion.criteria = new Criterion[] { productService, language, proximity }; // Creatives Creative creative1 = new Creative(); creative1.headline = "Standard Mars Trip"; creative1.line1 = "Fly coach to Mars"; creative1.line2 = "Free in-flight pretzels"; Creative creative2 = new Creative(); creative2.headline = "Deluxe Mars Trip"; creative2.line1 = "Fly first class to Mars"; creative2.line2 = "Unlimited powdered orange drink"; marsTourPromotion.creatives = new Creative[] { creative1, creative2 }; PromotionOperation operation = new PromotionOperation(); operation.@operator = Operator.ADD; operation.operand = marsTourPromotion; try { Promotion[] addedPromotions = promotionService.mutate( new PromotionOperation[] { operation }); Console.WriteLine("Added promotion ID {0} with name {1} to business ID {2}.", addedPromotions[0].id, addedPromotions[0].name, businessId); } catch (Exception ex) { throw new System.ApplicationException("Failed to add promotions.", ex); } }
/// <summary> /// Handles the Click event of the btnDownloadReport control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing /// the event data.</param> protected void OnDownloadReportButtonClick(object sender, EventArgs e) { ConfigureUserForOAuth(); 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 = Path.GetTempFileName(); 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 = "v201309"; // 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)); // Set the customer id. (user.Config as AdWordsAppConfig).ClientCustomerId = txtCustomerId.Text; ReportUtilities utilities = new ReportUtilities(user); utilities.ReportVersion = "v201309"; utilities.DownloadClientReport(definition, filePath); } catch (Exception ex) { throw new System.ApplicationException("Failed to download report.", ex); } Response.AddHeader("content-disposition", "attachment;filename=report.gzip"); Response.WriteFile(filePath); Response.End(); }
public virtual ManagedCustomerPage get(Selector serviceSelector) { object[] results = this.Invoke("get", new object[] { serviceSelector }); return ((ManagedCustomerPage) (results[0])); }
public virtual BudgetPage get(Selector selector) { object[] results = this.Invoke("get", new object[] { selector }); return ((BudgetPage) (results[0])); }
public virtual CampaignSharedSetPage get(Selector selector) { object[] results = this.Invoke("get", new object[] { selector }); return ((CampaignSharedSetPage) (results[0])); }
public virtual FeedMappingPage get(Selector selector) { object[] results = this.Invoke("get", new object[] { selector }); return ((FeedMappingPage) (results[0])); }
public virtual CampaignCriterionPage get(Selector serviceSelector) { object[] results = this.Invoke("get", new object[] { serviceSelector }); return ((CampaignCriterionPage) (results[0])); }
public virtual ProductServicePage get(Selector selector) { object[] results = this.Invoke("get", new object[] { selector }); return ((ProductServicePage) (results[0])); }
public virtual ExpressBusinessPage get(Selector selector) { object[] results = this.Invoke("get", new object[] { selector }); return ((ExpressBusinessPage) (results[0])); }
public virtual SharedCriterionPage get(Selector selector) { object[] results = this.Invoke("get", new object[] { selector }); return ((SharedCriterionPage) (results[0])); }
public virtual AdGroupBidLandscapePage getAdGroupBidLandscape(Selector serviceSelector) { object[] results = this.Invoke("getAdGroupBidLandscape", new object[] { serviceSelector }); return ((AdGroupBidLandscapePage) (results[0])); }
public virtual ConversionTrackerPage get(Selector serviceSelector) { object[] results = this.Invoke("get", new object[] { serviceSelector }); return ((ConversionTrackerPage) (results[0])); }
/// <summary> /// Handles the Click event of the btnGetCampaigns control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing /// the event data.</param> protected void OnGetCampaignsButtonClick(object sender, EventArgs e) { ConfigureUserForOAuth(); // Now proceed to make your API calls as usual. // Create a selector. Selector selector = new Selector(); selector.fields = new string[] {"Id", "Name", "Status"}; OrderBy orderByName = new OrderBy(); orderByName.field = "Name"; orderByName.sortOrder = SortOrder.ASCENDING; selector.ordering = new OrderBy[] {orderByName}; (user.Config as AdWordsAppConfig).ClientCustomerId = txtCustomerId.Text; try { CampaignService service = (CampaignService) user.GetService(AdWordsService.v201309.CampaignService); CampaignPage page = service.get(selector); // Display campaigns. if (page != null && page.entries != null && page.entries.Length > 0) { DataTable dataTable = new DataTable(); dataTable.Columns.AddRange(new DataColumn[] { new DataColumn("Serial No.", typeof(int)), new DataColumn("Campaign Id", typeof(long)), new DataColumn("Campaign Name", typeof(string)), new DataColumn("Status", typeof(string)) }); for (int i = 0; i < page.entries.Length; i++) { Campaign campaign = page.entries[i]; DataRow dataRow = dataTable.NewRow(); dataRow.ItemArray = new object[] {i + 1, campaign.id, campaign.name, campaign.status.ToString() }; dataTable.Rows.Add(dataRow); } CampaignGrid.DataSource = dataTable; CampaignGrid.DataBind(); } else { Response.Write("No campaigns were found."); } } catch (Exception ex) { Response.Write(string.Format("Failed to get campaigns. Exception says \"{0}\"", ex.Message)); } }
public virtual AdGroupAdPage get(Selector serviceSelector) { object[] results = this.Invoke("get", new object[] { serviceSelector }); return ((AdGroupAdPage) (results[0])); }
public virtual BiddingStrategyPage get(Selector selector) { object[] results = this.Invoke("get", new object[] { selector }); return ((BiddingStrategyPage) (results[0])); }
public virtual LocationCriterion[] get(Selector selector) { object[] results = this.Invoke("get", new object[] { selector }); return ((LocationCriterion[]) (results[0])); }