I've download the start code from here: http://goo.gl/Tcxkod and followed the instructions and installed the sample.py from here https://developers.google.com/api-client-library/python/start/installation:
alvas@ubi:~/git/UniversalCorpus/drive-cmd-line-sample$ python sample.py
Success! Now add code here.
But how do I dump pickle/json files onto the drive and then retrieve it to read from python?
I clicked on the dev documentation and there's no clue other than the repr and source code itself: https://developers.google.com/resources/api-libraries/documentation/drive/v2/python/latest/drive_v2.files.html#get
Go to Google API Console. Go to the Credentials page. Click the Download JSON button to download the client secret JSON file and securely store it in a local folder. This JSON file can then be used by Google Drive components and metadata wizard to access Google Drive via the OAuth method Installed Application (JSON) .
I tested PyDrive and I think it's pretty straigtforward. Here's what I did:
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)
# Upload a json file (will be identical for a pickle file)
json_file = drive.CreateFile()
json_file.SetContentFile('wopwop.json')
json_file.Upload() # Files.insert()
print json_file['title'], json_file['id']
# Download the same json file
same_json_file = drive.CreateFile({'id': json_file['id']})
same_json_file.GetContentFile('test.json') # Save Drive file as a local file
There's two "problems" with this code:
If you are not interested in using PyDrive, I strongly suggest you to read its code. If I had to do it, I would place 3 breakpoints (or print) in pydrive.files:
_FilesInsert on the line self.auth.service.files().insert(**param).execute()
_FilesUpdate on the line self.auth.service.files().update(**param).execute()
_DownloadFromUrl on the line self.auth.service._http.request(url) and in the constructor to see how he obtain the url (it's in self.metadata)You already have service with the code you downloaded in sample.py, so you only need to know what is in the param dictionary to understand what's going on.
However, you should use PyDrive ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With