Apps script, transfer file ownership - Is it possible with super admin account? - google-apps-script

I've been researching on using apps script to transfer file owner from one user to another, for files that are not owned by the script account. I saw posts with possible solutions using drive API, but is it possible to use DriveApp's file setOwner() to transfer a file's ownership when using a super admin account? Thank you.

No, Apps Script doesn't support domain-wide authority for Drive Access. You'll need to use Drive SDK and Service Accounts for that.
Please log an enhancement in Apps Script Issue Tracker if you want to track this with the team.

Related

Is it possible to create/deploy a google web app with a service account as its owner?

Google Apps Script project (more about this here)
Create script at script.new
Menu Publish -> deploy as a web app
Here you choose performed by me, user, etc. Accessed by ...
Is it possible to make it work with a service account as its owner? (so that it survives when you terminate the user's accounts later)
I would check out this awesome article stepping through the step-by-step approach to allow Google Apps Script to use a service account. This might work for your needs.
How to use GCP service accounts with Google Apps Script projects
One thing to note is that the Google Apps Script API itself does not work with service accounts. As per the documentation.
Hope this helps! Let me know if you need further assistance :)

Google Drive API Uses

I am creating one application when users can use his/her drive account to save documents. Can i use Drive API so the users save documents in drive? The users will use my app to upload pdf documents in his/her folder.
Yes you can use the Google Drive api to create, update and delete files on a users google drive account.
You Will need to use Oauth2 to have the user authenticate your application granting it access to their google drive account.
You should be aware that the Google drive api has a number of sensitive and restricted scopes which will make the verification process a little more complicated than it would be otherwise.
What you need to know about Google verification in 2021.

Why can't i transfer ownership of google drive folder and files to other? (OwnershipTransfer libary is being used)

The library I am using is from here.
The response has very little info to debug or I don't understand what is this. It supposed to be easy from what I read in the description.
Any help?
That's an intended behavior. From your screenshot, I'm assuming you're using a G Suite/Workspace account for your 5times.co.in email. Please take note that transferring files from one Workspace account to another workspace account or Gmail is not possible as of the moment.
This is a documented here: https://support.google.com/a/users/answer/9308960
You can transfer ownership of your Google Drive files and folders to someone else in your organization.
an alternative is to either use Shared Drive or download the file and re-upload it to your Gmail account.
A better way to do this is:
step-1: Transfer files from the drive (your Gdrive) to google cloud storage
step-2: Transfer files from google cloud storage to drive (new Gdrive, different organization)
Reference python code for file transfer between DRIVE & Google drive.
https://colab.research.google.com/drive/1Xc8E8mKC4MBvQ6Sw6akd_X5Z1cmHSNca

Save Files to Owner G-Drive(Google Script)

I have a web app created using google script which is distributed in a team,They will use it to upload some files.
I want to save those files into my drive rather than their own accounts.
According to my research I can only save it my account If I publish that app with option Execute as me and option who has access with anonymous.
But I want to Execute as user accessing this app option(that required user to authorized).
Anyone know how to solve this?
Create a service account and enable Domain-wide Delegation of Authority on it. Then you can execute saves to the Google Drive under your account. You'll need to leverage a Google OAuth2 library.
Here's a good one:
OAuth2 for Apps Script

Is it possible to integrate Google Spreadsheet into a cloud application and store all app/user data on only one Google Drive account?

Hi Google Drive SDK team on Stackoverflow. I need a personal reply from you guys as this question is important for the backend architecture of a cloud application we are working on.
We want to integrate Google Spreadsheet in the frontend of a cloud application, but we want to structure the backend in such a way that all
user application data/files is stored only on one main Google Drive and not in the user's Google Drive. Does the Google Drive SDK or other Google
products enable the capabilityneed? From the Google Drive SDK page the typical use case is that an app stores data in the user's own Google Drive account.
Our case is different and we want to store all data in our own Google Drive account. Looking forward to your reply. Thanks
https://developers.google.com/drive/v2/reference/files/copy#examples
Its possible but you need to read more about how oauth works and spreadsheet permissions (btw im not from the drive team).
If you will use the users tokens your only option would be to have a backend create the spreadsheet on your drive (with you as the owner) and share it with the user.
If you will use your own tokens and not the user's, you will need a backend to serve as proxy for spreadsheet operations. That way you dont give write permission to the user (so she cant change your data). Drawback of using your own tokens is that you will have quota issues with many users.
The first thing you need to do is decide which API you intend to use.
The link you posted is for the Drive API. This will allow you to upload and download spreadsheets, but not manipulate their contents.
If you require row or cell level access to a spreadsheet, that will use the Spreadsheets API. See https://developers.google.com/google-apps/spreadsheets/
Next decide how you will deal with permissions. You want a centrally owned spreadsheet, so you have three choices.
Proxy all of the access through a web server as suggested by #zig
Access the spreadsheet directly, but use a centrally provided access token
Use a Service Account