First point : i have a question please , is there the possibility to download a pdf file from my drive as doc or any other format using Google Drive API? just as we can do manualy on drive : open a pdf file as google documents and download it .
EDIT : Second point : what i did : connect to apidrive via quickstart. I Turned on the Drive API(Step1) , and Installed the Google Client Library (step2). after that, i tryed to upload a file from my HD to my drive using the code :
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
#1st authentification
gauth = GoogleAuth()
gauth.LocalWebserverAuth() # Creates local webserver and auto handles
authentication.
drive = GoogleDrive(gauth)
file1 = drive.CreateFile()
file1.SetContentFile('documt.pdf')
file1.Upload()
the next step in my plan, was to download 'documt.pdf' that i've just uploaded to drive , in a different format (.doc for example). So i searched how to do So, i've found the following script , even if it doesn't do what i exactly want (as the docs says) , it can only download Google Documents as pdf(the inverse of what i wanted) :
file_id = '1ZdR3L3qP4Bkq8noWLJHSr_iBau0DNT4Kli4SxNc2YEo'
request = drive_service.files().export_media(fileId=file_id,
mimeType='application/pdf')
fh = io.BytesIO()
downloader = MediaIoBaseDownload(fh, request)
done = False
while done is False:
status, done = downloader.next_chunk()
print "Download %d%%." % int(status.progress() * 100)
however even this code shows an error :
Traceback (most recent call last):
File "C:\Users\OU\AppData\Local\Programs\Python\Python36-
32\download_from_drive.py", line 10, in <module>
request = drive_service.files().export_media(fileId=file_id,
NameError: name 'drive_service' is not defined
my client_secrets file looks like (don't know if it does have a relation to the problem): {"web":{"client_id":"xxxxx.apps.googleusercontent.com","project_id":"xxxx","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://accounts.google.com/x/oauth2/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/c","client_secret":"erm-xxxx","redirect_uris":["http://localhost:8080/"],"javascript_origins":["http://localhost:8080"]}}
can anyone help me find a answer to my question (first point), and a solve the Error (second point)?
THANK YOU Very Much
Finnally, i've answered to my question.
for the first point : it's not allowed to download a pdf as another format. However we can upload the file in the first place with the google docs format application/vnd.google-apps.document
even if it's a pdf. and i will work really fine.
For the second point: because the 1st point issue is solved now, i don't need to fix the Error. cause what i wanted works perfectly good.