API Changes for Google Drive’s folder structure and sharing models - google-drive-api

I used to use below Google Drive API to move my existing file to another drive folder
drive.files().update(fileId=cloudFile['id'],addParents=sharefile,media_body=media).execute()
I just got an email said that the Google Drive folder structure is changed and I'm not allowed to use "addParent" to share filers anymore. I was wondering how can I do this with drive API? I don't want to re-write the entire code, and I'm looking for the simplest way to replace addParents API.

Answer:
Instead of giving a file multiple parents, you can create a shortcut to another Drive file instead (such as a folder).
More Information:
You can use the shortcuts functionality of Google Drive instead of the multiple parents functionality to emulate the kind of behaviour. From the Documentation:
Shortcuts are files that link to other files on Google Drive.
Shortcuts are Drive files with the application/vnd.google-apps.shortcut MIME type, that point to another file or folder on a Google Drive. You can read more about this here.
References:
Create a Shortcut to a Drive File
Find files & folders with Google Drive shortcuts
G Suite and Drive MIME Types

Related

Google Drive Url System Design

I noticed this behavior on Google Drive.
When a link is created for a file on Google Drive, the link is valid until the file is deleted.
Moving the file to another folder(s) does not affect the behavior of url.
I will like to understand how they achieved this at scale.
This is an expected behavior when moving files to another folder within your google drive. This is because a google file URL is usually composed of the following:
product domain
product
document Id
Therefore, moving the file to another folder within the google drive will not affect the file URL because file path is not included in the URL format.
References:
Google Sheets API Overview
Docs API

Is it possible to list folders in a google drive folder

Using google drive api https://developers.google.com/drive/v3/web/about-sdk how can you list folders in a specified folder?
How?
Raster
I initially thought this did not work using v3. Was mistaken. The only criteria seems to be that I use the api to create the nested folder. Than create the folder manually

Opening a file on Google Drive directly in a Google Drive App

If I open the shareable link I have got for a file from Google Drive in the browser, I always get either to the Drive's internal preview program or to a download page (See below).
I would like to know whether there is a programmatic way to launch a specific drive-connected application (with confirmed access permissions) to open a file for which I have the link (and thus, the ID as well).
I don't want to do this through the drive's interface, but rather within my program. Let's say I want to let the users browse their files and open them in the browser with their default app as they have defined it on their drive (and let's say I already know that app).
To make it clear, I just want to achieve what Google Drive's interface does in the browser: You click a file, and it opens in a new tab in your default app.
In my opinion, this is possible with the use of Advanced Drive Service and Drive Service.
Advanced Drive Service
The advanced Drive service allows you to use the Google Drive web API in Apps Script. Much like Apps Script's built-in Drive service, this API allows scripts to create, find, and modify files and folders in Google Drive. In most cases, the built-in service is easier to use, but this advanced service provides a few extra features, including access to custom file properties as well as revisions for files and folders.
and for the Drive Service, you can use getUrl() method to get the URL that can be used to open the File in a Google App like Drive or Docs.
This service allows scripts to create, find, and modify files and folders in Google Drive.
Detailed information and sample codes regarding these services can be found in the documentations.

Google Apps Script - Add file from Google Drive

First of all I want you to know that I'm not talking about uploading a file from users computer drive.
What Im aiming to do is to be able to allow users to add a file from their Google Drive to a specific folder in my Google Drive. I've searched around (a lot) and I can't find anything similar.
Have you ever seen this window? I could use something like it (it's in spanish but im sure you've seen it before). It allows you to upload a file from your pc or from your Google Drive:
Is it possible to access this pop up windows through Google Apps Script? If not, what are the alternatives?
What you have listed there is google picker. It can be used in apps script.
https://developers.google.com/apps-script/guides/dialogs#file-open_dialogs
The docs for Drive picker can be found at:
https://developers.google.com/picker/docs/
What you can do, is use the Drive Picker API to allow users to chose files from their google drive.
Then once you have the File, you can add it to your folder.
https://developers.google.com/apps-script/reference/drive/folder#addFile(File)
https://developers.google.com/picker/docs/

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