Granting Team Drive access to a service account in Google Drive API v3 for .NET

Hey everyone! I’m trying to figure out how to let a Google service account access our company’s Team Drive. We want to use it in our .NET backend app to upload and download files.

Here’s what I’ve done so far:

  • Set up a project in Google Cloud Platform
  • Turned on the Drive API
  • Made a service account with a key
  • Gave it Editor/Owner role
  • Set up G Suite Domain-wide Delegation

But I’m stuck. When I try to upload stuff, it just goes to the service account’s private drive. Not ideal!

Does anyone know how to make it work with our Team Drive? Or maybe a way to share files from the service account’s drive to our team?

I’ve looked through the docs but can’t find anything clear on this. Any tips or tricks would be super helpful! Thanks in advance!

hey there! i’ve run into this before. make sure u add the service account email directly to the team drive members. in ur .NET code, use the driveId parameter with the team drive ID and set supportsAllDrives to true. Also, double check ur using the right scopes. good luck!

Having worked with Google Drive API extensively, I can attest that Team Drive access can be tricky. One often overlooked step is adding the service account’s email to the Team Drive explicitly. This is separate from domain-wide delegation. Go to your Team Drive, click ‘Add members’, and paste the service account’s email.

For your .NET implementation, ensure you’re using the correct scopes. You’ll need ‘https://www.googleapis.com/auth/drive’ for full access. When making API calls, always include ‘supportsAllDrives=true’ and ‘corpora=drive’ parameters. Also, specify the Team Drive ID using ‘driveId’.

If you’re still having issues, double-check that your G Suite admin has approved the necessary API scopes for domain-wide delegation. This is a common oversight that can cause headaches.

I’ve dealt with this issue before and found that the key is to properly set your API requests. You must ensure that your service account is given the necessary permissions on the Team Drive, sometimes by adding it explicitly as a member. When initializing your DriveService, use the service account credentials and impersonate a user with access to the Team Drive. For a successful API call, include the driveId parameter (using your Team Drive’s ID) and set supportsAllDrives to true. This approach took some trial and error but eventually worked reliably.