为什么我得到的路径System.UnauthorizedAccessException的访问“Google.Apis.Auth”被拒绝 [英] Why do I get System.UnauthorizedAccessException Access to the path 'Google.Apis.Auth' is denied
问题描述
我已经实现谷歌驱动器功能进行文件管理的工作在本地系统中运行良好,但每当我主持这Godaddy的服务器上扔了以下错误
System.UnauthorizedAccessException的
的路径访问Google.Apis.Auth'被拒绝。
块引用>
下面的代码我是使用:
UserCredential凭证= GoogleWebAuthorizationBroker.AuthorizeAsync(
新ClientSecrets
{
客户端Id = System.Configuration.ConfigurationManager.AppSettings [GDriveClientId],//获取客户端ID从web.config中。
ClientSecret = System.Configuration.ConfigurationManager.AppSettings [GDriveClientSecret] //获取ClientSecret从web.config中。
},
新的[] {} DriveService.Scope.Drive,
System.Configuration.ConfigurationManager.AppSettings [GDriveCreatedByUser],//从web.config中获取用户名。
CancellationToken.None)。结果;
返回凭证;
我使用VS2010,对于上述功能
解决方案拓展什么钱德里卡已经说过,ASP.NET用户需要读取和写入权限谷歌API客户端的OAuth2库的永久存储文件夹。
它的默认值是
Environment.SpecialFolder.ApplicationData code>名为Google.Apis.Auth的文件夹(这通常对应于
C:\Users\your-用户name\AppData\Roaming
)。
此外,另一个文件夹,可以作为的
GoogleWebAuthorizationBroker.AuthorizeAsync()
方法
<预类=郎-CS prettyprint-覆盖>VAR文件夹= System.Web.HttpContext.Current.Server.MapPath(/程序App_Data / MyGoogleStorage);
UserCredential凭证= GoogleWebAuthorizationBroker.AuthorizeAsync(
新ClientSecrets
{
客户端Id =PutYourClientIdHere,
ClientSecret =PutYourClientSecretHere
} ,
新的[] {} DriveService.Scope.Drive,
用户,
CancellationToken.None,
新FileDataStore(文件夹))结果。
返回凭证;
请参阅:的 https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth#credentials 和的 https://developers.google.com/accounts/docs/OAuth2
I have implemented google drive functionality for file management its working fine in local system but whenever i hosted it on Godaddy server it throw following error
System.UnauthorizedAccessException Access to the path 'Google.Apis.Auth' is denied.
Following code i am using :
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;
I am using VS2010,IIS 7 for above functionality
解决方案Expanding what Chandrika has already said, the ASP.NET user needs read and write permissions to the Google API Client OAuth2 Library's permanent storage folder .
Its default value is a folder named "Google.Apis.Auth" in
Environment.SpecialFolder.ApplicationData
(which usually corresponds toC:\Users\your-user-name\AppData\Roaming
).Alternatively, another folder can be provided as the last parameter of the
GoogleWebAuthorizationBroker.AuthorizeAsync()
method: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;
See: https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth#credentials and https://developers.google.com/accounts/docs/OAuth2
这篇关于为什么我得到的路径System.UnauthorizedAccessException的访问“Google.Apis.Auth”被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!