i trying download files google drive , have drive's url.
i have read google api talks drive_service , medioio, requires credentials( json file/oauth). unable idea how working.
also, tried urllib2 urlretrieve, case files drive. tried 'wget' no use.
tried pydrive library. has upload functions drive no download options.
any appreciated. thanks.
if "drive's url" mean shareable link of file on google drive, following might help:
import requests def download_file_from_google_drive(id, destination): url = "https://docs.google.com/uc?export=download" session = requests.session() response = session.get(url, params = { 'id' : id }, stream = true) token = get_confirm_token(response) if token: params = { 'id' : id, 'confirm' : token } response = session.get(url, params = params, stream = true) save_response_content(response, destination) def get_confirm_token(response): key, value in response.cookies.items(): if key.startswith('download_warning'): return value return none def save_response_content(response, destination): chunk_size = 32768 open(destination, "wb") f: chunk in response.iter_content(chunk_size): if chunk: # filter out keep-alive new chunks f.write(chunk) if __name__ == "__main__": file_id = 'take id shareable link' destination = 'destination file on disk' download_file_from_google_drive(file_id, destination)
the snipped not use pydrive, nor google drive sdk, though. uses requests module (which is, somehow, alternative urllib2).
when downloading large files google drive, single request not sufficient. second 1 needed - see wget/curl large file google drive.
Comments
Post a Comment