1

I am not sure what I missed, but I generated the "json" file and connected it to the code after installing the nuget package. I have access to read files from the google drive folders but I cannot create a file. It keeps giving me a permission error.

var fileMetadata = new Google.Apis.Drive.v3.Data.File();
fileMetadata.Name = "SomeFile.txt";
fileMetadata.MimeType = "application/vnd.google-apps.drive-sdk";
var request = service.Files.Create(fileMetadata);
request.Fields = "id";
var file = request.Execute();

I have tried changing the scopes to .Drive and all the rest but it still didn't work. What should I do? Should it be something that I missed in the site where i generated the json before even installing the nuget package of the API?

Error: Google.Apis.dll but was not handled in user code

Additional information: Google.Apis.Requests.RequestError

Insufficient Permission [403]

Errors [

Message[Insufficient Permission] Location[ - ] Reason[insufficientPermissions] Domain[global]

Thanks

Shakshuka
  • 19
  • 2
  • 8

2 Answers2

0

From the documentation of Drive API, the suggested action for this 403 error is report to the user that there is a need to ask for those permissions in order to update the file. You may also want to check user access levels in the metadata retrieved by files.get and use that to change your UI to a read only UI. Also make sure you follow the steps in Authorization.

{
  "error": {
    "errors": [
      {
        "domain": "global",
        "reason": "insufficientFilePermissions",
        "message": "The user does not have sufficient permissions for file {fileId}."
      }
    ],
    "code": 403,
    "message": "The user does not have sufficient permissions for file {fileId}."
  }
}

Also the Files:create need this scope:

https://www.googleapis.com/auth/drive.file
https://www.googleapis.com/auth/drive.appdata

For more information, check this related SO question, it may give you an idea on how to solve this.

Community
  • 1
  • 1
KENdi
  • 7,576
  • 2
  • 16
  • 31
0

EDIT: The problem is solved. If it happens to you regardless to all the changes in the scope, it is probably denied for any reason from the dialog that is supposed to be shown and you supposed to select "Allow" in your browser. For example, I tried from another computer and it loaded up the browser for me in debug (it only does it once), and asked to allow access. After that, everything worked. For current computer that it's denying access, go to drive in the browser and remove the application that the API is using, then it will give you the dialog again.

Shakshuka
  • 19
  • 2
  • 8