问题描述
我已经实现了用于文件管理的谷歌驱动器功能,它在本地系统中工作正常,但是每当我将它托管在 Godaddy 服务器上时,它都会抛出以下错误
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拒绝访问路径Google.Apis.Auth".
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 来实现上述功能
I am using VS2010,IIS 7 for above functionality
推荐答案
扩展 Chandrika 已经说过的内容,ASP.NET 用户需要对 Google API 客户端 OAuth2 库的永久存储文件夹的读写权限.
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 .
其默认值为Environment.SpecialFolder.ApplicationData
中名为Google.Apis.Auth"的文件夹(通常对应于C:Usersyour-user-nameAppData漫游
).
Its default value is a folder named "Google.Apis.Auth" in Environment.SpecialFolder.ApplicationData
(which usually corresponds to C:Usersyour-user-nameAppDataRoaming
).
或者,可以提供另一个文件夹作为 GoogleWebAuthorizationBroker.AuthorizeAsync()
方法:
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;
请参阅:https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth#credentials 和 https://developers.google.com/accounts/docs/OAuth2
这篇关于为什么我得到 System.UnauthorizedAccessException 对路径“Google.Apis.Auth"的访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!