python - Google Picker and download the selected file -


i have managed integrate google picker. have fileid , access_token. need download selected file in end in python. have followed documentation on google developers if use python library have authenticate user again not suitable in case. please enlighten me if can download file format.

thanks in advance.

this simple sample script downloading files using access token , file id without google library. , sample supposes files (images , videos) except google docs, said. flow follows.

flow :

  1. retrieve filename , mimetype.
  2. create filename retrieved filename , mimetype. if filename doesn't have extension on google drive, script adds extension filename using mimetype , save it. if filename has extension on google drive, script uses original filename , save it.
  3. download file , save created filename. if want save file specific directory, please set yourself.

sample script :

import mimetypes import os.path import requests accesstoken = "### access token ###" fileid = "### file id ###" fileinf = requests.get(     "https://www.googleapis.com/drive/v3/files/" + fileid,     headers={"authorization": "bearer " + accesstoken}, ) filename = fileinf.json()["name"] temp, ext = os.path.splitext(filename) filename = filename if ext != "" else filename + mimetypes.guess_extension(fileinf.json()["mimetype"]) r = requests.get(     "https://www.googleapis.com/drive/v3/files/" + fileid + "?alt=media",     headers={"authorization": "bearer " + accesstoken}, ) open(filename, "wb") f:     f.write(r.content) 

if not helpful you, i'm sorry.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -