问题
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