/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); // Limit the fields returned. String fields = "nextPageToken,items(id,name,type)"; ReportList reports; String nextPageToken = null; do { // Create and execute the report list request. ReportsResource.ListRequest request = service.Reports.List(profileId); request.Fields = fields; request.PageToken = nextPageToken; reports = request.Execute(); foreach (Report report in reports.Items) { Console.WriteLine("{0} report with ID {1} and name \"{2}\" was found.", report.Type, report.Id, report.Name); } // Update the next page token. nextPageToken = reports.NextPageToken; } while (reports.Items.Any() && !String.IsNullOrEmpty(nextPageToken)); }
private Report FindReport(DfareportingService service, long profileId) { // [START find_report] MOE:strip_line Report target = null; ReportList reports; String nextPageToken = null; do { // Create and execute the reports list request. ReportsResource.ListRequest request = service.Reports.List(profileId); request.PageToken = nextPageToken; reports = request.Execute(); foreach (Report report in reports.Items) { if (IsTargetReport(report)) { target = report; break; } } // Update the next page token. nextPageToken = reports.NextPageToken; } while (target == null && reports.Items.Any() && !String.IsNullOrEmpty(nextPageToken)); // [END find_report] MOE:strip_line if (target != null) { Console.WriteLine("Found report {0} with name \"{1}\".", target.Id, target.Name); return(target); } Console.WriteLine("Unable to find report for profile ID {0}.", profileId); return(null); }