DEV Community

Joakim Nystrom
Joakim Nystrom

Posted on

Changing ownership for files using Google Drive v3 API

This is just a warning fellow developers to waste hours to come to the same conclusion as I did.

With the v3 version of the Drive Api one cannot transfer ownership for files and folders using the Api for users using gmail.com.

If it's within a Workspace accounts you might pull it off. However, since approval is needed for transfer these days, you need to modify the permission request

// 💾 The old way
 const transaction = await drive.permissions.create({
        fileId: fileId, 
        resource: {
          role: "owner", // easy-peasy....
          type: "user",
          emailAddress: newOwnerEmail,
        }
      });
Enter fullscreen mode Exit fullscreen mode
// 🙄 The new way
 const transaction = await drive.permissions.create({
        fileId: fileId, 
        resource: {
          role: "writer", // Share it to the new owner
          type: "user",
          emailAddress: newOwnerEmail,
          domain: 'everything-but-gmail.com',
        },
        transferOwnership: true, // 
      });
Enter fullscreen mode Exit fullscreen mode

Hope this helps anyone out there!

API Trace View

Struggling with slow API calls? 👀

Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay