Sample uses Install-Package Google.Apis.AnalyticsReporting.v4
Public Shared Function getServiceInitializer() As BaseClientService
Dim serviceAccountCredentialFilePath = "Path to Json service account key file" REM from Google Developers console
Dim myKeyEMail = "[email protected]" REM from Google Developers console
Dim scope = Google.Apis.AnalyticsReporting.v4.AnalyticsReportingService.Scope.AnalyticsReadonly
Try
Dim credential
Using stream As New FileStream(serviceAccountCredentialFilePath, FileMode.Open, FileAccess.Read)
credential = GoogleCredential.FromStream(stream).CreateScoped(scope)
End Using
Dim Initializer As New BaseClientService.Initializer()
Initializer.HttpClientInitializer = credential
Initializer.ApplicationName = "SRJCGMail"
Dim service As New AnalyticsReportingService(Initializer)
Return service
Catch ex As Exception
Console.WriteLine(ex.Message)
Return Nothing
End Try
End Function