C#.NET - OAuth的 - 无限加载时间和访问路径“Google.Apis.Auth”被

2019-10-23 08:10发布

我想从我的域名我的谷歌分析帐户连接。 我做这个在localhost上不与下面的代码的问题:

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

后来我从我的域名尝试这样做,但我得到了以下错误:

访问路径“Google.Apis.Auth”被拒绝。

我解决了这个问题通过增加“变种文件夹”“新FileDataStore(文件夹)”是这样的:

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

这仍然适用于本地主机(在谷歌认证页面的弹出窗口)的罚款。 在域它使加载页面的无限长的时间。 (在谷歌认证页面不弹出)

我试图在OAuth的添加域“客户端ID为Web应用程序”

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