Skip to content

Instantly share code, notes, and snippets.

@agencethelio
Created November 9, 2018 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agencethelio/3c3041c9b801e9e5baf218272dba81d6 to your computer and use it in GitHub Desktop.
Save agencethelio/3c3041c9b801e9e5baf218272dba81d6 to your computer and use it in GitHub Desktop.
Traitement du service Report de GoogleAnalytics
private static Report GetReport(string sViewId, string startDate, string endDate)
{
string[] scopes = new string[] { AnalyticsReportingService.Scope.Analytics };
var credential_google = GoogleCredential.FromJson(_jsonCertificat).CreateScoped(scopes);
AnalyticsReportingService analyticsreporting = new AnalyticsReportingService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential_google,
ApplicationName = _projectId,
});
DateRange dateRange = new DateRange() { StartDate = startDate, EndDate = endDate };
ReportRequest reportRequest = new ReportRequest
{
ViewId = sViewId,
DateRanges = new List<DateRange>() { dateRange },
Dimensions = _dimensions,
Metrics = _metrics
};
List<ReportRequest> requests = new List<ReportRequest>
{
reportRequest
};
// Create the GetReportsRequest object.
GetReportsRequest getReport = new GetReportsRequest() { ReportRequests = requests };
// Call the batchGet method.
GetReportsResponse response = analyticsreporting.Reports.BatchGet(getReport).Execute();
return response.Reports[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment