#Installing PyDrive
!pip install PyDrive
#Importing modules
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
#Authenticating and creating the PyDrive client
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
#Getting the file
downloaded2 = drive.CreateFile({'id':"1QGtoo1wqCP2yrjl8kFu4kTfjWqh3EOdt"}) # replace the id with id of file you want to access
downloaded2.GetContentFile('estructura_cc_felipe.xlsx')
但是它会引发这样的错误:
代码语言:
javascript
复制
Go to the following link in your browser:
https://accounts.google.com/o/oauth2/auth?client_id=32555940559.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&code_challenge=WkM1RS8Flu1_txc3jn4V_FfutgZuRaHSzYbDvs134PM&code_challenge_method=S256&access_type=offline&response_type=code&prompt=select_account
Enter verification code: ··········
---------------------------------------------------------------------------
AuthorizationError Traceback (most recent call last)
<ipython-input-2-bb96e063f8ef> in <module>()
7 #Authenticating and creating the PyDrive client
----> 8 auth.authenticate_user()
9 gauth = GoogleAuth()
10 gauth.credentials = GoogleCredentials.get_application_default()
1 frames
/usr/local/lib/python3.6/dist-packages/google/colab/auth.py in authenticate_user(clear_output)
147 context_manager = _output.temporary if clear_output else _noop
148 with context_manager():
--> 149 _gcloud_login()
150 _install_adc()
151 colab_tpu_addr = _os.environ.get('COLAB_TPU_ADDR', '')
/usr/local/lib/python3.6/dist-packages/google/colab/auth.py in _gcloud_login()
97 _os.remove(name)