0

I am trying to create new folder MY_FOLDER in Google Drive using Drive API, using the quick starter example and adding more to it as I read through the https://developers.google.com/drive/v3/web/quickstart/dotnet.

My scope is set as:

static string[] Scopes = { DriveService.Scope.DriveFile };

And I create service like this

private static void CreateService()
{
    using (var stream =
        new FileStream("client_secret.json", FileMode.Open, FileAccess.ReadWrite))
    {
        string credPath = System.Environment.GetFolderPath(
            System.Environment.SpecialFolder.Personal);
        credPath = Path.Combine(credPath, ".credentials/drive-dotnet-quickstart.json");

        credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
            GoogleClientSecrets.Load(stream).Secrets,
            Scopes,
            "user",
            CancellationToken.None,
            new FileDataStore(credPath, true)).Result;
        Console.WriteLine("Credential file saved to: " + credPath);
    }

    // Create Drive API service.
    service = new DriveService(new BaseClientService.Initializer()
    {
        HttpClientInitializer = credential,
        ApplicationName = ApplicationName,
    });
}

As per example on this page [https://developers.google.com/drive/v3/web/folder], 2, I am creating new folder

var fileMetadata = new File()
{
    Name = "MY_FOLDER",
    MimeType = "application/vnd.google-apps.folder"
};
var request = driveService.Files.Create(fileMetadata);
request.Fields = "id";
var file = request.Execute();
Console.WriteLine("Folder ID: " + file.Id);

The error I get reads "Insufficient Permissions [403]"

UPDATE I created credentials as described in same Google tutorial at https://developers.google.com/drive/v3/web/quickstart/dotnet

pixel
  • 9,653
  • 16
  • 82
  • 149
  • Sounds like you didn't add your API credentials properly. I would double check on that. – Slepz Feb 24 '17 at 23:52
  • or maybe the *debug* version is not authorized –  Feb 25 '17 at 00:07
  • I am doing it using the explanation in the link above in the UPDATE section. – pixel Feb 25 '17 at 08:04
  • Make sure that you grant the service account permission to access the file. You may refer [here](http://stackoverflow.com/questions/33075595/google-drive-upload-returns-403-insufficient-permission). You could also try changing your Google Drive Scope to `Google_Service_Drive::DRIVE`. Here's a related [thread](http://stackoverflow.com/questions/32309136/google-drive-api-client-python-insufficient-permission-for-files-insert) which might help. – abielita Feb 28 '17 at 08:50

0 Answers0