Just Rudy
Just Rudy

Reputation: 700

TeamDrive in Google Drive API

I'm trying the code below, obtained from their docs here. I'm unable to compile, I get an exception message:

enter image description here

Maybe I'm not understanding the TeamDrive concept correctly?

I'm not sure where the issue is. Below is the code snippet I have:

        var teamDriveMetadata = new TeamDrive()
        {
            Name = "Project Resources"
        };

        var requestId = System.Guid.NewGuid().ToString();
        var request = service.Teamdrives.Create(teamDriveMetadata, requestId);
        request.Fields = "id";

        var teamDrive = request.Execute();
        Console.WriteLine("Team Drive ID: " + teamDrive.Id);

        Console.WriteLine("Done.");
        Console.Read();

Below is the auth setup:

        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,
              "MyKey",
              CancellationToken.None,
              new FileDataStore(credPath, true)).Result;
            Console.WriteLine("Credential file saved to: " + credPath);
        }
        // Create Drive API service.
        var service = new DriveService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = ApplicationName
        });

Upvotes: 0

Views: 584

Answers (1)

user8015139
user8015139

Reputation: 26

FYI: I ran the sample code linked without issue. I have a test project that has the proper permissions already established. I pasted the linked code into that project, and had to resolve "var request" conflicting with the same in my existing code. Once resolved the code ran without issue.

As previously suggested I would recommend focusing on resolving your permissions/scopes.

Upvotes: 1

Related Questions