8

It is rather obvious that this simplest recommended way which also provides the simplest API for reading the files from a drive folder ―

from google.colab import drive
drive.mount('/content/gdrive')

― does not allow access to files/folders shared with/by you in Google Drive, but only allows access to your own drive's files, making its use less of a fit for shared notebooks (or at least, shared notebooks that need to access data from shared google drive folders).

Is it possible to access google drive folders shared by/with you using the same API, or any of the other ones which rely on google drive sharing permissions and not "anyone with the link can access" google drive hyperlinks?

I believe all other ways require the use and hard-coding of file id's, whereas the API mentioned above can access drive files by name, which at times can be simpler to maintain.

Can you use the same API for shared Google Drive files?

matanster
  • 15,072
  • 19
  • 88
  • 167
  • Here's BTW the code behind this API for now https://github.com/googlecolab/colabtools/blob/master/google/colab/drive.py – matanster Dec 21 '18 at 12:10

1 Answers1

11

A simple solution for shared files is to add them to you Drive by right clicking on the file in the 'shared with me' list in Drive and selecting the 'Add to Drive' item. Afterward, the file will appear in /content/drive/My Drive/

enter image description here

Bob Smith
  • 36,107
  • 11
  • 98
  • 91
  • 1
    That's a great suggestion thanks :-) it should allow all people who have access to run the same code without tampering google drive file ids. – matanster Dec 22 '18 at 05:35
  • 2
    Thank you for your answer ! But seems interface has been changed in 2020, and I have trouble doing like that, please take a look, if you have time: https://stackoverflow.com/q/61525486/625396 – Alexander Chervov Apr 30 '20 at 14:20
  • 1
    It seems the explantation is the following: mounting google drive by web interface button "Mount Drive" has a bug: https://stackoverflow.com/a/61560765/625396 – Alexander Chervov May 02 '20 at 14:25
  • As Alexender Chenderov [said](https://stackoverflow.com/a/61560765/2842067), it works only if the Google Drive is mounted with code, and not the UI button. – Alexey Jan 27 '23 at 10:17