我在生成令牌時遇到了一些與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