0

Google analytics API .NET

Hi i recive this message

"Google.Apis.Auth.OAuth2.Responses.TokenResponseException' occurred in Google.Apis.dll
Additional information: Error:"invalid_grant", Description:"", Uri:""

this is my code

String serviceAccountEmail = "semanadev@gmail.com";
var certificate = new X509Certificate2("SiteViews-0c1a357186d9.p12", "notasecret", X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
               new ServiceAccountCredential.Initializer(serviceAccountEmail)
               {
                Scopes = new[] { AnalyticsService.Scope.AnalyticsReadonly }
               }.FromCertificate(certificate));

AnalyticsService analyticsService = new Google.Apis.Analytics.v3.AnalyticsService(new BaseClientService.Initializer()
   {
    HttpClientInitializer = credential,
    ApplicationName = "SiteViews"
    });
            GaData results = analyticsService.Data.Ga.Get("ga:72785204", "2014-10-10", "2014-10-20", "ga:users").Execute();
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • invalid grant normally has something to do with the time. Check the time on our machine make sure its correct. You did get the service account email from Dev console correct? and you added you gave it access to Google analytics? – Linda Lawton - DaImTo Oct 22 '14 at 06:57
  • I was using wrong account, i set the service account email and worked – Semana Developer Oct 23 '14 at 16:29

0 Answers0