/// <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)
        {
            string query = "SELECT CampaignId, AdGroupId, Id, Criteria, CriteriaType, Impressions, " +
                           "Clicks, Cost FROM CRITERIA_PERFORMANCE_REPORT WHERE Status IN [ENABLED, PAUSED] " +
                           "DURING LAST_7_DAYS";

            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 = "v201406";
                // ClientReport report = utilities.GetClientReport(query, format);
                //
                // // 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 = "v201406";
                utilities.DownloadClientReport(query, DownloadFormat.GZIPPED_CSV.ToString(), filePath);
                Console.WriteLine("Report was downloaded to '{0}'.", filePath);
            } catch (Exception ex) {
                throw new System.ApplicationException("Failed to download report.", ex);
            }
        }
Example #2
0
        public static void DownloadReport(AdWordsUser user, string fileName)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("SELECT ");
            foreach (string item in GoogleStaticReportFields.AD_PERFORMANCE_REPORT_FIELDS)
            {
                sb.Append(item);
                sb.Append(",");
            }
            sb.Remove(sb.Length - 1, 1);             // removing last ","
            sb.Append(" FROM " + ReportDefinitionReportType.AD_PERFORMANCE_REPORT.ToString());
            sb.Append(" DURING YESTERDAY ");
            //  string query = "SELECT CampaignId, AdGroupId, Id, Criteria, CriteriaType, Impressions, " +
            //"Clicks, Cost FROM CRITERIA_PERFORMANCE_REPORT WHERE Status IN [ACTIVE, PAUSED] " +
            //"DURING LAST_7_DAYS";

            string filePath = "D:\\" + fileName;

            try
            {
                ReportUtilities utilities = new ReportUtilities(user);
                utilities.ReportVersion = "v201302";
                utilities.DownloadClientReport(sb.ToString(), DownloadFormat.GZIPPED_CSV.ToString(), filePath);
                Console.WriteLine("Report was downloaded to '{0}'.", filePath);
            }
            catch (Exception ex)
            {
                throw new System.ApplicationException("Failed to download report.", 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();
        }
Example #4
0
        /// <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[] { "ENABLED", "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 = "v201406";
                // 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 = "v201406";
                utilities.DownloadClientReport(definition, filePath);
                Console.WriteLine("Report was downloaded to '{0}'.", filePath);
            } catch (Exception ex) {
                throw new System.ApplicationException("Failed to download report.", ex);
            }
        }
Example #5
0
        /// <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(string p_user, string p_repName, string[] p_fields)
        {
            AdWordsUser user = new AdWordsUser();

            ((AdWordsAppConfig)user.Config).ClientCustomerId = p_user;

            ReportDefinition definition = new ReportDefinition();

            definition.reportName     = "Nov2013_ " + p_repName;
            definition.reportType     = (ReportDefinitionReportType)Enum.Parse(typeof(ReportDefinitionReportType), p_repName);
            definition.downloadFormat = DownloadFormat.GZIPPED_CSV;
            definition.dateRangeType  = ReportDefinitionDateRangeType.CUSTOM_DATE;



            // Create selector.
            Selector selector = new Selector();

            selector.dateRange = new Google.Api.Ads.AdWords.v201309.DateRange();
            string start = string.Format("{0:yyyy-MM-dd}", "2013-11-01");

            start = start.Replace("-", "");
            selector.dateRange.min = start;

            string end = string.Format("{0:yyyy-MM-dd}", "2013-11-30");

            end = end.Replace("-", "");
            selector.dateRange.max = end;



            selector.fields = p_fields;

/*
 *    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 + p_repName +"_"+p_user+ ".GZ";
            string filePath = "C:\\TEMP\\GOOGLE" + Path.DirectorySeparatorChar + p_repName + "_" + p_user + ".GZ";

            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, false, filePath);
                Console.WriteLine("Report was downloaded to '{0}'.", filePath);
            } catch (Exception ex) {
                throw new System.ApplicationException("Failed to download report.", ex);
            }
        }