/// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="reportType">The report type to be run.</param>
        public void Run(AdWordsUser user, ReportDefinitionReportType reportType)
        {
            using (ReportDefinitionService reportDefinitionService =
                       (ReportDefinitionService)user.GetService(
                           AdWordsService.v201802.ReportDefinitionService)) {
                try {
                    // Get the report fields.
                    ReportDefinitionField[] reportDefinitionFields = reportDefinitionService.getReportFields(
                        reportType);
                    if (reportDefinitionFields != null && reportDefinitionFields.Length > 0)
                    {
                        // Display report fields.
                        Console.WriteLine("The report type '{0}' contains the following fields:", reportType);

                        foreach (ReportDefinitionField reportDefinitionField in reportDefinitionFields)
                        {
                            Console.Write("- {0} ({1})", reportDefinitionField.fieldName,
                                          reportDefinitionField.fieldType);
                            if (reportDefinitionField.enumValues != null)
                            {
                                Console.Write(" := [{0}]", String.Join(", ", reportDefinitionField.enumValues));
                            }
                            Console.WriteLine();
                        }
                    }
                    else
                    {
                        Console.WriteLine("This report type has no fields.");
                    }
                } catch (Exception e) {
                    throw new System.ApplicationException("Failed to retrieve fields for report type.", e);
                }
            }
        }
Exemplo n.º 2
0
        private void GetReportFields_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);
                ReportDefinitionReportType reportType = (ReportDefinitionReportType)Enum.Parse(typeof(ReportDefinitionReportType), ReportNamesListBox.SelectedItem.ToString());
                ReportDefinitionService    reportDefinitionService = (ReportDefinitionService)User.GetService(AdWordsService.v201302.ReportDefinitionService);

                // Get the report fields.
                ReportDefinitionField[] reportDefinitionFields = reportDefinitionService.getReportFields(reportType);
                foreach (ReportDefinitionField reportDefinitionField in reportDefinitionFields)
                {
                    this.AvailableReportFields.AppendText(reportDefinitionField.fieldName + ",");
                    List <object> rowObjects = new List <object>();

                    this.dataGridView.Rows.Add(
                        reportDefinitionField.fieldName,
                        reportDefinitionField.displayFieldName,
                        reportDefinitionField.fieldType,
                        reportDefinitionField.isBeta,
                        reportDefinitionField.canFilterSpecified,
                        reportDefinitionField.canSelect,
                        reportDefinitionField.canSelectSpecified,
                        reportDefinitionField.enumValuePairs,
                        reportDefinitionField.enumValues,
                        reportDefinitionField.isBetaSpecified,
                        reportDefinitionField.isEnumType,
                        reportDefinitionField.isEnumTypeSpecified,
                        reportDefinitionField.xmlAttributeName,
                        reportDefinitionField.canFilter);
                }

                this.AvailableReportFields.Text.Remove(this.AvailableReportFields.Text.Length - 1, 1);
            }
            catch (Exception ex)
            {
                this.response.Text = string.Format("{0} Inner: {1}", ex.Message, ex.InnerException.Message);
            }
        }