C# 对路径Google.api.Auth的访问被拒绝
我试图实现google calendar事件同步功能,将事件从本地应用程序安排到google calendar。它在本地系统中运行良好,但每当我在服务器上部署它时,它就会抛出以下错误 System.UnauthorizedAccessException:对路径“Google.api.Auth”的访问被拒绝 下面是我正在使用的代码C# 对路径Google.api.Auth的访问被拒绝,c#,asp.net-mvc,google-api,google-calendar-api,google-api-dotnet-client,C#,Asp.net Mvc,Google Api,Google Calendar Api,Google Api Dotnet Client,我试图实现google calendar事件同步功能,将事件从本地应用程序安排到google calendar。它在本地系统中运行良好,但每当我在服务器上部署它时,它就会抛出以下错误 System.UnauthorizedAccessException:对路径“Google.api.Auth”的访问被拒绝 下面是我正在使用的代码 var credential = GoogleWebAuthorizationBroker.AuthorizeAsync( new ClientSecr
var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = "xxx-9khdjsqifkj2amsji2jce37p8lfn0166.apps.googleusercontent.com",
ClientSecret = "ZdsrCa-uwG3GmpVLTfYDli-S",
},
new[] { CalendarService.Scope.Calendar },
"user",
CancellationToken.None).Result;
// Create the service.
var service = new CalendarService(new BaseClientService.Initializer
{
HttpClientInitializer = credential,
ApplicationName = Summary,
});
默认情况下,Google.Net客户端库使用FileDatastore()文件数据存储默认情况下将凭据存储在%appData%中。当您在运行应用程序的用户下运行应用程序时,您似乎无权访问%appData%
string credPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, ".credentials/", System.Reflection.Assembly.GetExecutingAssembly().GetName().Name);
var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = "xxx4671204-9khdjsqifkj2amsji2jce37p8lfn0166.apps.googleusercontent.com",
ClientSecret = "ZdsrCa-uwG3GmpVLTfYDli-S",
},
new[] { CalendarService.Scope.Calendar },
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
确保credPath是您有权写入的地方。我在GitHub上有一个示例,还有一个关于filedatastore如何工作的教程默认情况下,Google.Net客户端库使用filedatastore()文件数据存储默认情况下将凭据存储在%appData%中。当您在运行应用程序的用户下运行应用程序时,您似乎无权访问%appData%
string credPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, ".credentials/", System.Reflection.Assembly.GetExecutingAssembly().GetName().Name);
var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = "xxx4671204-9khdjsqifkj2amsji2jce37p8lfn0166.apps.googleusercontent.com",
ClientSecret = "ZdsrCa-uwG3GmpVLTfYDli-S",
},
new[] { CalendarService.Scope.Calendar },
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
确保credPath是您有权写入的地方。我在GitHub上有一个示例,我有一个关于filedatastore如何工作的教程你应该在你的项目上重新生成秘密你已经与世界共享了你的客户id这是你应该保密的事情。你应该在你的项目上重新生成秘密你已经与世界共享了你的客户id这是你应该保密的事情你应该保密。