Reputation: 372
recently colab removed the ability to connect to google drive from different accounts other than the one you were logged into in google drive. There was a workaround someone posted with the following code which worked great, until now...
!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 gdrive
%cd gdrive
!mkdir "My Drive"
%cd ..
%cd ..
!google-drive-ocamlfuse "/content/gdrive/My Drive"
the auth.authenticate_user()
line now gives a popup that resembles the recently updated normal authentication process giving this popup
I go through the process and log into my other account and I am met with this message. is there any workaround to this?
the reason this matters is that I have unlimited storage on my edu account for free but I couldn't get my edu account to work the paid version of colab due to security restrictions on my universities system, hence I use a payed colab on my personal account and store my data on the edu account
Upvotes: 4
Views: 9987
Reputation: 372
edit: do it all in one cell without printing unneeded information
edit2 april 28th 2022: changed !sudo apt install google-drive-ocamlfuse >/dev/null 2>&1
to a new line because sudo apt update
was failing on colab and preventing it from running the install line.
!sudo echo -ne '\n' | sudo add-apt-repository ppa:alessandro-strada/ppa >/dev/null 2>&1 # note: >/dev/null 2>&1 is used to supress printing
!sudo apt update >/dev/null 2>&1
!sudo apt install google-drive-ocamlfuse >/dev/null 2>&1
!google-drive-ocamlfuse
!sudo apt-get install w3m >/dev/null 2>&1 # to act as web browser
!xdg-settings set default-web-browser w3m.desktop >/dev/null 2>&1 # to set default browser
%cd /content
!mkdir gdrive
%cd gdrive
!mkdir "My Drive"
!google-drive-ocamlfuse "/content/gdrive/My Drive"
then just click the link Failure("Error opening URL:https://accounts.google.com/o/oauth2/auth?client_id=56492...
and authorize your account
I found one solution I am not sure how fast it it in terms of connection to grive etc but it mounts at least. I figured this out thanks to link1, link2 first run this, you'll be promted to (click in the box) and then click enter
!sudo add-apt-repository ppa:alessandro-strada/ppa
!sudo apt update
!sudo apt install google-drive-ocamlfuse
!google-drive-ocamlfuse
you'll see this output pictured below, just click the link and authorize your account.
next for some reason you'll need to install a browser, even though you already authorized your account, so run this
!sudo apt-get install w3m # to act as web browser
!xdg-settings set default-web-browser w3m.desktop # to set default browser
finally mount it
%cd /content
!mkdir gdrive
%cd gdrive
!mkdir "My Drive"
!google-drive-ocamlfuse "/content/gdrive/My Drive"
Upvotes: 11