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, // In order to make a request for approval
      });
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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

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

Okay