How to access Team Drive using service account with Google Drive .NET API v3

前端 未结 1 402
清歌不尽
清歌不尽 2020-12-16 04:36

Does anyone know which configurations should be done to grant Google service account an access to a Team Drive which is already created?

The idea is to use a service

相关标签:
1条回答
  • 2020-12-16 05:33

    Here are the steps to grant access based on the documentation from the comment in addition to the steps in the question.

    These steps require an account with Services and Apps admin role.

    • Sign-in to Google Admin and go to Apps -> G Suite -> Drive and Docs -> Sharing Settings sub-menu and select ON from the Sharing options
    • Click on the Manage Team Drives sub-menu and click on the Team Drive you want to grant access to
    • Click on ADD MEMBERS in the Member access pop-up
    • Enter the service account Account ID (email), choose access level (I chose Full), check the Skip sending notification and click on SEND

    Assuming the authentication part is set up properly, here is a simple code which gets service account's Team Drives:

    var teamDriveList = service.Teamdrives.List();
    
    teamDriveList.Fields = "teamDrives(kind, id, name)";
    
    var teamDrives = teamDriveList.Execute().TeamDrives;
    
    if (teamDrives != null && teamDrives.Count > 0)
    {
        foreach (var drive in teamDrives)
        {
            Console.WriteLine("{0} ({1})", drive.Name, drive.Id);
        }
    }
    

    More on the Fields parameter syntax here

    0 讨论(0)
提交回复
热议问题