gpt4 book ai didi

c# - 为什么我得到 System.UnauthorizedAccessException Access to the path 'Google.Apis.Auth' is denied

转载 作者:太空狗 更新时间:2023-10-29 21:12:52 28 4
gpt4 key购买 nike

我已经实现了用于文件管理的谷歌驱动器功能,它在本地系统中运行良好,但每当我将它托管在 Godaddy 服务器上时,它就会抛出以下错误

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

我正在使用以下代码:

UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = System.Configuration.ConfigurationManager.AppSettings["GDriveClientId"],//Get ClientID from web.config.
ClientSecret = System.Configuration.ConfigurationManager.AppSettings["GDriveClientSecret"]//Get ClientSecret from web.config.
},
new[] { DriveService.Scope.Drive },
System.Configuration.ConfigurationManager.AppSettings["GDriveCreatedByUser"],//Get UserName from web.config.
CancellationToken.None).Result;

return credential;

我正在使用 VS2010,IIS 7 来实现上述功能

最佳答案

扩展 Chandrika 已经说过的内容,ASP.NET 用户需要对 Google API 客户端 OAuth2 库的永久存储文件夹具有读写权限。

它的默认值是 Environment.SpecialFolder.ApplicationData 中名为“Google.Apis.Auth”的文件夹(通常对应于 C:\Users\your-user-name\AppData\漫游)。

或者,可以提供另一个文件夹作为 GoogleWebAuthorizationBroker.AuthorizeAsync() 的最后一个参数方法:

var folder = System.Web.HttpContext.Current.Server.MapPath("/App_Data/MyGoogleStorage");

UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = "PutYourClientIdHere",
ClientSecret = "PutYourClientSecretHere"
},
new[] { DriveService.Scope.Drive },
"user",
CancellationToken.None,
new FileDataStore(folder)).Result;

return credential;

参见:https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth#credentialshttps://developers.google.com/accounts/docs/OAuth2

关于c# - 为什么我得到 System.UnauthorizedAccessException Access to the path 'Google.Apis.Auth' is denied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23405767/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com