使用服务帐户连接到Google API会在analytics api .net错误上提供invalid_grant

时间:2014-10-21 21:23:07

标签: c# google-analytics google-api google-oauth google-api-dotnet-client

Google analytics API .NET

嗨,我回复了这条消息

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

这是我的代码

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();

0 个答案:

没有答案