C#.net - OAuth - Unlimited load time & Access to the path 'Google.Apis.Auth' is denied

蹲街弑〆低调 提交于 2019-12-13 00:30:33

问题


I'm trying to connect from my domain to my Google Analytic account. I've done this on localhost without problems with the following code:

string clientId = "******************.apps.googleusercontent.com";
string clientSecret = "*****************";
string gaUser = "**************";
string gaApplication = "**";
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
   new ClientSecrets {
      ClientId = clientId,
      ClientSecret = clientSecret
   },
      new[] { AnalyticsService.Scope.AnalyticsReadonly },
      gaUser,
      CancellationToken.None
  ).Result;

service = new AnalyticsService(new BaseClientService.Initializer() {
  HttpClientInitializer = credential,
  ApplicationName = gaApplication
});

Afterwards i've tried this from my domain, but i got the following error:

Access to the path 'Google.Apis.Auth' is denied.

I fixed this by adding the 'var folder' and the 'new FileDataStore(folder)' like this:

string clientId = "******************.apps.googleusercontent.com";
string clientSecret = "*****************";
string gaUser = "**************";
string gaApplication = "**";

var folder = System.Web.HttpContext.Current.Server.MapPath("/App_Data/MyGoogleStorage");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
   new ClientSecrets {
      ClientId = clientId,
      ClientSecret = clientSecret
   },
      new[] { AnalyticsService.Scope.AnalyticsReadonly },
      gaUser,
      CancellationToken.None,
      new FileDataStore(folder)
  ).Result;

service = new AnalyticsService(new BaseClientService.Initializer() {
  HttpClientInitializer = credential,
  ApplicationName = gaApplication
});

This still works fine on localhost (The google authentication page popups). On the domain it keeps loading the page for an unlimited time. (The google authentication page doesn't popup)

I've tried to add the domain at OAuth "Client ID for web application"

来源:https://stackoverflow.com/questions/30783411/c-net-oauth-unlimited-load-time-access-to-the-path-google-apis-auth-is

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!