0

I'm having some issues with google API while generating the token. The code works fine in the local machine but the publish version gives "Access is denied" error. I know that must be something related with the folder's permissions, but I don't know how to solve it. Actually our authorization function is like this:

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;
}

The website is written in ASP NET MVC 5 and is hosted in Azure websites.

Thank you for your help.

2 Answers2

0

The code works fine in the local machine but the publish version gives "Access is denied" error.

I have a same issue after I deploy the web application to Azure websites.

enter image description here

I refer to “Web applications (ASP.NET MVC)” section from this article to get user Credential and use DriveService, and I find it works fine on Azure websites.

Fei Han
  • 26,415
  • 1
  • 30
  • 41
0

I finally decided to use only my own drive account. So I created a token and I'm using it all the time. I followed these topics:

1.- Create a token for Google Drive API: https://stackoverflow.com/a/19766913/4965910

2.- Add Google API to MVC properly and use our token: GoogleWebAuthorizationBroker in MVC For Google Drive Access

You must be careful, is easy to get stuck in some steps.

This only woks for ASP NET MVC applications with one drive account. I know is not solves the problem directly, this way is avoided it. Hope it helps.

Community
  • 1
  • 1