访问“Google.Apis.Auth”路径被拒绝mvc c#

时间:2017-05-02 20:37:11

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

我已实施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;

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

1 个答案:

答案 0 :(得分:0)

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

  

新的FileDataStore(“Google.Apis.Auth”)

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