转载地址:https://zhuanlan.zhihu.com/p/33344222?utm_source=wechat_session&utm_medium=social
先运行下面这些代码,来安装必要的库、执行授权。
!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}
运行的时候应该会看到下图所示的结果:
看见那个链接之后,点击它,复制验证码并粘贴到文本框里。
授权完成后,就可以挂载Google Drive了:
!mkdir -p drive
!google-drive-ocamlfuse drive