我在生成令牌时遇到了一些与Google API有关的问题。该代码在本地机器上正常工作,但发布版本提供“访问被拒绝”错误。我知道这必须与文件夹的权限有关,但我不知道如何解决它。其实我们的授权功能是这样的:Google API授权访问在生成令牌时被拒绝
public static DriveService AuthenticateOauth(string clientId, string clientSecret, string userName)
{
String folder = System.Web.HttpContext.Current.Server.MapPath("/App_Data/MyGoogleStorage/");
string[] scopes = new string[] { DriveService.Scope.Drive };
// here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData%
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret }
, scopes
, userName
, CancellationToken.None
, new FileDataStore(folder)).Result;
DriveService service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Drive API",
});
return service;
}
该网站是写在ASP NET MVC 5和Azure的网站托管。
谢谢你的帮助。
您是否在[Google Developer Console](https://console.developers.google.com/apis/credentials)上为您的Production环境设置了正确的凭据? –
是的,我有他们的代码,并在当地正常工作。我想在发布版本中必须是相同的。 – ajmena