Browse Files and folders uploaded on Google Drive - google-drive-api

I'm writing from Italy (sorry for mistakes), my question is about GOOGLE DRIVE API and
I'm writing here because the G-Suite support wrote me to contact you, I'm not a programmer.
The big question is: how can I browse folders and files uploaded on my Google Drive Api?
I write you what apppened.
I wanted to use a backup program to save in a planned way files and folders an Google Drive.
I downloaded the program (Iperius Backup) and followed the instructions.
To understand on what I did, I paste the link of the instructions below:
http://www.iperiusbackup.net/en/backup-to-google-drive/
http://www.iperiusbackup.net/en/how-to-enable-google-drive-api-and-get-client-credentials/
I tried the software and everything worked.
So I opened Google Drive but the back-upped files weren't there.
Seen that there was something not clear, I have erased all the files on my Google Drive. I wanted to make sure that it was empty, hoping to erase also “hidden files”(...even if I thought it wouldn't have been so simple...)
To make sure that everything was erased (also “hidden files”), I tried to restore files from the backup software but unfortunately, the software worked well...the files were still there, somewhere...
This means that I have saved through the backup software files and folders on Google Drive “Api”, but I cannot manage them.
How can I have access to my space in Google Drive Api and erase all my files and folders that are still there?
Thank you in advance for the help,
best regards,
Stefano

To list all files in your drive, you can use Files: list.
This method accepts the q parameter, which is a search query
combining one or more search terms. For more information, see the
Search for Files and Team Drives guide.
You can use the Try it now or use the sample code given in a specific language you are using.
To delete/erase a file, use Files: delete.
Permanently deletes a file by ID. Skips the trash. The currently
authenticated user must own the file or be an organizer on the parent
for Team Drive files. Try it now or see an example.

Related

User with edit privileges made files I own not viewable by me

I shared a folder containing files and subfolders with files with multiple users and gave them edit permissions. One users account has modified the viewing ability(?) of every file and subfolder they had access to. From my account when I open the top level folder I see it empty but I know these files are still there because I own the majority of them and my drive storage amount hasn't changed.
The user claims they have no idea how it happened so maybe that it was an app they unknowingly gave drive access to?
Is there any way I can fix this from the Google Drive web interface? I found Google Apps Scripts has access to the Drive API, should I find a script that can mass change the permissions?
Only the owner can delete the file.
The files were removed from the folder but were not deleted.
Therefore, they take up disk space.
To view files outside the folder, follow these steps:
https://drive.google.com/drive/search?q=is:unorganized%20owner:me
Excuse my bad English
Venca

How can I use Google Apps Script to move files between personal Google Drives and Team Drives?

Recently, I gained access to Google Team Drive via Google's Team Drive early adopter program.
I created a Google Docs file called Hello, world!, and then wrote a short Google Apps Script function which uses an addFile() method to update which Google Drive folder the file is attached to:
function move_or_link_file() {
var source = DriveApp.getFolderById("<sourceID>");
var fileiter = source.getFilesByName("Hello, world!");
var dest = DriveApp.getFolderById("<destID>");
while (fileiter.hasNext()) {
var file = fileiter.next();
dest.addFile(file);
}
}
Typically, a Google Drive folder has a URL which matches the following pattern: https://drive.google.com/drive/folders/<alphanumericID>. Although it's perhaps a bit inelegant, I can test my code under various operating scenarios and conditions by simply opening different combinations of Google Drive folders in a web browser, selecting the <alphanumericID> portion of the folder URL, and then manually copy-and-pasting values for this string into <sourceID> and <destID>.
After testing, I am able to identify four different input conditions which result in three distinct behaviors:
Case 1: <sourceID> and <destID> are both folders in my personal Google Drive:
In this case, the script behaves in effect as if it's creating a symbolic link: the Hello, world! file now appears in both directories. Note that it really is the same file, not two identical copies: for example, if I open the document, then the document URL, like the folder URLs, also follows a pattern: https://docs.google.com/document/d/<documentID>/edit. I can tell the file is the same because when I open it, the URL for the document shares the same <documentID>, regardless of which parent folder I use to access it.
For case 1, I can also get the script to behave more like a mv command by simply appending an additional line, source.removeFile(file); to the end of the file iterator loop.
Case 2: <sourceID> is a folder in my personal Google Drive while <destID> is a folder in a Team Drive:
In this case, the script behaves like a mv command by default, rather than as a symbolic link, even without the additional call to the removeFile() method that I mentioned in case 1: i.e., the Hello, world! file simply disappears from my personal drive and reappears in the Team Drive.
Case 3: <sourceID> and <destID> are both folders in a Google Team Drive:
This results in an error message from Google Apps Script: Cannot use this operation on a Team Drive item. (line 7, file "move_or_link_file").
Case 4: <sourceID> is a folder in a Team Drive while <destID> is a folder in my personal Google Drive:
Same error as for Case 3.
Now here is the really weird part: the GSuite graphical user interface (i.e., what you are using when you access Google Drive files and folders via the web browser) offers a Move command via a popup window that appears when you right-click on a file. This GUI version of the Unix-like mv command behaves identically for all four of the above cases: it doesn't matter whether you are moving a folder back and forth between a personal drive or team drive, or internally within a drive, it works correctly and moves the file to where you would expect it to go, every time.
So, I presume it must be possible to implement a mv command via Google's API, somehow, given that they've evidently done it already for users of the GUI interface.
Thus my question: given that it's empirically possible to move files back and forth between arbitrary combinations of folders in personal drives and team drives, how would I actually do it, using only the API calls provided by Google Apps Script?
Also, a bonus question: suppose that, similar to Case 1, instead of moving a file between two different folders in the same Team Drive, I actually wanted to create a symbolic link attaching the file to both folders--how would I use the Google API to do that as well? (I.e., how can I get Case 3 to behave more like Case 1?)
The Google Team Drives only recently started allowing scripts in general. I would imagine the file move you were able to achieve in case 2 is not even intended. There are still several limitations on the team drive (for example you cannot move folders).
For Case 1 I can simply point out that your script is not actually a move command. You should actually imagine Google Drive folders as Gmail tags. A file can have no folders at all. Your script merely assigns a tag to the file and as such it can appear in many folders (just like an email can have many Gmail tags and appear in each tags "folder").
It works in case 2 because Team Drive is a seperate entity from your personal drive. In essence, when you added it to the team drive you had to give up the ownership of the file. As far as I have seen, team drive considers that adding a file to it means that it should be removed from all other parents. I would assume that is why in cases 3 and 4 you cannot move any items. The owner is the team drive itself, however the commands are being sent as a regular Gsuite user.
Drive REST api was recently (~begining of March) updated to work with team drives: https://developers.google.com/drive/v3/web/about-teamdrives so I believe that technically what you are looking for can be done, however considering there are still several limitations on team drives, I don't think it will be documented as well as it could be.

Google drive search : files own by me but not in any folder (previously in a shared folder but now deleted)

I got some Google Drive folders shared with me by a collaborator, I put a lot of files into it and we did work like this for months now.
This guy did a delete on the folder and now my files are all lost, I can make a search for my files but there are so many and I don't know the names of all those files.
Is there a way to make a search on those files not listed in any folders but owned by me?
in your drive, search for
is:unorganized owner:me
https://support.google.com/a/answer/6008339?hl=en
Had the EXACT same problem. Found this thread by Googling, but had a harder time finding a complete solution. Found it here from Ally Marie:
https://productforums.google.com/forum/#!topic/docs/xOvsElpcPZA
Synopsis: You can get a list of everything you own and look for the item in that list. Click the down arrow in the Google Drive search box and select Ownership > Owned by me.

Prevent deletion of files in Google Drive

I am trying to prevent deletion of all files uploaded to specific folder in Google drive. The idea is several people will be able to upload files to this drive, but they should never be able to delete it.
I thought of putting a Google apps script to achieve this, like letting the script run every x interval and getTrashedFiles and set isTrashed to false. But what if the user is able to delete it from trash too?
Is there a foolproof way?
Or is Google Drive not the right answer at all?
Any other service can help me which is simple for people uploading the files?
TIA
its possible but the way you are doing it isnt practical or tamperproof.
instead write a little apps script webapp that allows uploading files to the given folder where you are owner and only writter.
publish it to run as you with permissions to anyone (or your domain). they will be able to add files and view but not change or remove them (and you will be the owner of all uploaded files).
to support uploading files already in drive (move them to the folder) is also possible but with more code.

google drive folder information

I would like to use Google Drive to push files in various folders onto a remote computer. I would like this to be a one-way transaction so the people using the computer cannot write to Google Drive.
However, when I use the following C# code to get the files from Google Docs I only get the file names, not their directories where they will be on the remote computer. This won't work because some files in different directories have the same name. Is there a way to programmatically get directory information from these files?
Alternately, if I could set up the Google Drive folder to be read-only, that would accomplish my goal and probably be easier. Can this be done?
You should use the Google Drive API to list all files and check the parents field of each of them to map those files into folders:
https://developers.google.com/drive/v2/reference/files#resource