GoogleWebAuthorizationBroker.AuthorizeAsync()
在(农场,4.5网络)临时服务器上失败,但在本地服务器上工作良好。我已经遵循了帮助行上的每一段代码,但仍然没有用。
下面是我的代码:
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<---
根据我读到的其他笔记,这是由于服务器端的权限问题,但对于农场站点,我无法再控制任何权限。
有趣的是,当我将一个批准的凭证从我的本地服务器复制到临时服务器时,一切都正常了!临时服务器似乎没有能力(或没有权限)启动屏幕,要求用户批准令牌!
我该如何解决这个问题?
发布于 2016-05-21 12:26:49
我花了几个小时解决同样的问题,最终找到了一篇帮助我解决这个问题的帖子。这篇文章在这里http://answers.flyppdevportal.com/MVC/Post/Thread/7819b19d-07d0-4584-a061-cace0688bfb2?category=sharepointdevelopment
在这段代码为我工作的开发服务器上,在credPath文件夹中创建了一个令牌响应文件(请参阅上面代码中的这个变量)。
我只是把这个文件复制到临时服务器上,在那里它对我不起作用。为我解决了这个问题..
这可能是因为页面向用户显示(在开发服务器中工作),而在这种情况下,页面无法显示,这导致了此错误。再一次,这都是理论上的,但上面的解决方案对我来说是有效的。
https://stackoverflow.com/questions/36017661
复制相似问题