【问题标题】:Access to the path 'Google.Apis.Auth' is denied mvc c#访问路径“Google.Apis.Auth”被拒绝 mvc c#
【发布时间】:2017-05-02 20:37:11
【问题描述】:

我已经实现了用于文件管理的 Google Drive 功能。它在本地系统中运行良好,但每当我将它托管在我的服务器上时,它都会引发以下错误:

System.UnauthorizedAccessException: Access to the path 'Google.Apis.Auth' is denied. 


 string[] scopes = new string[] { "https://www.googleapis.com/auth/contacts.readonly" }; 


 UserCredential credential =    GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets {
                ClientId = "clientId", ClientSecret = "clientSecret" }, 
                scopes, "test2", CancellationToken.None, new FileDataStore("Google.Apis.Auth")).Result;

或者,我提供另一个文件夹作为相对路径,代码挂起。

【问题讨论】:

  • 你需要显示抛出异常的代码

标签: c# asp.net-mvc google-drive-api unauthorizedaccessexcepti


【解决方案1】:

Google .Net 客户端库默认使用FileDatastore 将凭据存储在%AppData% 目录中。当以下代码验证时:

new FileDataStore("Google.Apis.Auth")

将在执行代码的机器上的%AppData% 目录中创建一个文件夹。当您在任何用户下运行应用程序时,您显然无法访问 %AppData% 目录。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-02
    • 2014-06-17
    • 2010-11-29
    • 1970-01-01
    相关资源
    最近更新 更多