GoogleWebAuthorizationBroker.AuthorizeAsync在登台服务器

时间:2016-03-15 17:04:07

标签: c# api web-applications calendar

GoogleWebAuthorizationBroker.AuthorizeAsync()在(farmed,4.5 NET)登台服务器上失败,但在本地服务器上运行良好。我已经关注了帮助热线上的每个代码仍无济于事。

这是我的代码:

String gpath = Server.MapPath("credentials/siteAPI.json");
UserCredential credential;

string credPath = Server.MapPath("credentials");

using (var stream = new FileStream(gpath, FileMode.Open, FileAccess.Read))
{
      credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    new[] { CalendarService.Scope.Calendar },//
                    "xx@ccc.com",
                    CancellationToken.None,
                     new AppDataFileStore(credPath)
                    ).Result;
}

我收到了这个错误:

System.AggregateException: One or more errors occurred.
---> System.ComponentModel.Win32Exception: Access is denied
    at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)
    at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__1.MoveNext() in C:\Users\mdril\Documents\GitHub\google-api-dotnet-client\Src\GoogleApis.Auth.DotNet4\OAuth2\GoogleWebAuthorizationBroker.cs:line 59
--- End of inner exception stack trace ---
    at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
    at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
    at System.Threading.Tasks.Task`1.get_Result()
    at z2.Page_Load(Object sender, EventArgs e) in e:\hostingspaces\cal1234\mysitecalendar.com\wwwroot\z2.aspx.cs:line 169
---> (Inner Exception #0) System.ComponentModel.Win32Exception (0x80004005): Access is denied
    at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)
    at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__1.MoveNext() in C:\Users\mdril\Documents\GitHub\google-api-dotnet-client\Src\GoogleApis.Auth.DotNet4\OAuth2\GoogleWebAuthorizationBroker.cs:line 59<---

根据我读到的其他说明,这是由于服务器端的权限问题,但对于养殖网站,我无法控制任何权限。

有趣的是,当我将其中一个已批准的凭据从我的本地服务器复制到登台服务器时,一切正常!似乎登台服务器无法(或没有权限)启动屏幕以要求用户进行令牌批准!

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

我花了好几个小时处理同样的问题,最后发现了一篇帮我解决问题的帖子。 帖子在这里http://answers.flyppdevportal.com/MVC/Post/Thread/7819b19d-07d0-4584-a061-cace0688bfb2?category=sharepointdevelopment

在此代码对我有用的开发服务器上,在credPath中创建了一个令牌响应文件(请参阅上面代码中的此变量)。

我刚刚将此文件复制到暂定服务器上,但它并不适用于我。 这解决了我的问题..

这可能是因为页面显示了同意网页(在开发服务器中工作)给用户,并且在这种情况下无法显示导致此错误的页面。 这也是所有理论,但上述解决方案对我有用。

相关问题