Update:
Unfortunately, From Jan 20, 2022, The small solution based on Blue’s solution and the similar solutions isn’t working anymore (Reference). You can use my old solution again…
Update2:
From Mars 30, 2022, my old solution isn’t working too! I find another solution (Phillip’s solution) that is working now.
Phillip’s Solution:
This solution is based on Phillip’s post. You can follow his post for more information.
Follow these steps:
- Run the below code:
!sudo add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!sudo apt-get update -qq 2>&1 > /dev/null
!sudo apt -y install -qq google-drive-ocamlfuse 2>&1 > /dev/null
!google-drive-ocamlfuse
- From the previous step, you get an error like this. Click on the link that locates in the previous error message and authenticate your account.
Failure(“Error opening
URL:https://accounts.google.com/o/oauth2/auth?client_id=… “)
- Run the below code:
!sudo apt-get install -qq w3m # to act as web browser
!xdg-settings set default-web-browser w3m.desktop # to set default browser
%cd /content
!mkdir drive
%cd drive
!mkdir MyDrive
%cd ..
%cd ..
!google-drive-ocamlfuse /content/drive/MyDrive
You must get this message:
Access token retrieved correctly.
My Old Solution
!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse
from google.colab import auth
auth.authenticate_user()
from oauth2client.client import GoogleCredentials
creds = GoogleCredentials.get_application_default()
import getpass
!google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL
vcode = getpass.getpass()
!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}
%cd /content
!mkdir drive
%cd drive
!mkdir MyDrive
%cd ..
%cd ..
!google-drive-ocamlfuse /content/drive/MyDrive
Blue’s Solution
from google.colab import drive
drive._mount('/content/drive')