Google Drive API: Uploading & Downloading Files

Google Drive API: Uploading & Downloading Files


36 comments

  1. I have problems about downloading!In Python My code falls in service.files().export  with message export 'only supports google docs'.In my drive i have a xls . Try with pdf mime type (i assume convert xls->pdf), tried with xlsx, xls and a spreadsheet as mimetype too.

  2. in DriveV2, you can export Google Docs using the exportLinks? Now in DriveV3, using the TRY-IT, it only returns the MiMETYPE and no exportlinks. How is this easier for developers?

  3. Hello Mr. Wesley Chun
    My name is Tiska, i'm a college student. Recently I'm learning Google Drive API and I'm interested to learn more, because i want to develop the google drive apps for research in my college. would you mind to answering some question about drive API?
    and may i know your personal email account?
    thank you ^.^

  4. Google Drive API is hard to integrate in iOS.
    https://github.com/google/google-api-objectivec-client-for-rest/issues
    lots of issue not solve. Developers need to take a lot of time to solve these issues.

  5. I cant seem to get this right. It keeps throwing errors for me. Here is the error message
    CODE:
    from _future_ import print_function
    import os

    from apiclient import discovery
    from apiclient.discovery import build
    from httplib2 import Http
    from oauth2client import file, client, tools

    try:
    import argparse
    flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
    except ImportError:
    flags = None

    SCOPES = 'https://www.googleapis.com/auth/drive.file'
    store = file.Storage('storage.json')
    creds = store.get()
    if not creds or creds.invalid:
    flow = client.flow_from_clientsecrets('client_secret.json', scope=SCOPES)
    creds = tools.run_flow(flow, store, flags)
    if flags else tools.run(flow, store)

    DRIVE = build('drive', 'v3', http=creds.authorize(Http()))

    FILES = (
    ('hello.txt', None),
    ('hello.txt', 'application/vnd.google-apps.document')
    )

    for filename, mimeType in FILES:
    metadata = {'name': filename}
    if mimeType:
    metadata['mimeType'] = mimeType

    res = DRIVE.files().create(body=metadata, media_body=filename).execute()
    if res:
    print('Uploaded "%s" (%s) ' % (filename, res['mimeType']))

    if res:
    MIMETYPE = 'application/pdf'
    data = DRIVE.files().export(fileId=res['id'], mimeType=MIMETYPE).execute()
    res, data = DRIVE._http.request(res['exportLinks'][MIMETYPE])
    if data:
    fn = '%s.pdf' % os.path.splitext(filename)[0]
    with open(fn, 'wb') as fh:
    fh.write(data)
    print('Downloaded "%s" (%s)' % (fn, MIMETYPE))

    ERROR:

    /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /Users/raymondm/PycharmProjects/HelloWorld/Demos/v3_download_files.py
    Traceback (most recent call last):
    File "/Users/raymondm/PycharmProjects/HelloWorld/Demos/v3_download_files.py", line 35, in <module>
    res = DRIVE.files().create(body=metadata, media_body=filename).execute()
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/googleapiclient/discovery.py", line 815, in method
    mimetype=media_mime_type)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
    return wrapped(*args, **kwargs)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/googleapiclient/http.py", line 548, in _init_
    fd = open(self._filename, 'rb')
    FileNotFoundError: [Errno 2] No such file or directory: 'hello.txt'

  6. I run the same code and I had these errors: Can you help me please?

    Traceback (most recent call last):
    File "c:update_costsuploader.py", line 32, in <module>
    res = DRIVE.files().create(body=metadata, media_body=filename).execute()
    File "C:UsersllollAnaconda3libsite-packagesgoogleapiclientdiscovery.py", line 811, in method
    mimetype=media_mime_type)
    File "C:UsersllollAnaconda3libsite-packagesoauth2client_helpers.py", line 133, in positional_wrapper
    return wrapped(*args, **kwargs)
    File "C:UsersllollAnaconda3libsite-packagesgoogleapiclienthttp.py", line 550, in _init_
    fd = open(self._filename, 'rb')
    FileNotFoundError: [Errno 2] No such file or directory: 'hello.txt'

  7. Whatever it May be it's a better lesson for everyone's to understand the living stength of human beings and a life of others need.

  8. Whatever it May be it's a better lesson for everyone's to understand the living stength of human beings and a life of others need.

  9. So, I am supposed to upload videos files greater than several hundred MBs, So, to upload them I am first calling my server side code of C# asp.net and then handing over the file to google drive. Isn't any direct way of uploading files? javascript for asp.net servers? No?

  10. Why php download code
    Fatal error: Uncaught exception 'Google_Service_Exception' with message '{

    "error": {

    "errors": [

    {

    "domain": "global",

    "reason": "fileNotExportable",

    "message": "Export only supports Google Docs."

    }

    ],

    "code": 403,

    "message": "Export only supports Google Docs."

    }

    }

    ' in C:AppServwwwgooglevendorgoogleapiclientsrcGoogleHttpREST.php:118

    Stack trace:

    #0 C:AppServwwwgooglevendorgoogleapiclientsrcGoogleHttpREST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttpPsr7Response), Object(GuzzleHttpPsr7Request), NULL)

    #1 [internal function]: Google_Http_REST::doExecute(Object(GuzzleHttpClient), Object(GuzzleHttpPsr7Request), NULL)

    #2 C:AppServwwwgooglevendorgoogleapiclientsrcGoogleTaskRunner.php(181): call_user_func_array(Array, Array)

    #3 C:AppServwwwgooglevendorgoogleapiclientsrcGoogleHttpREST.php(58): Google_Task_Runner->run()

    #4 C:AppServwwwgooglevendorgoogleapiclientsrcGoogleClient.php(779): Google_Http_REST::execute(Object(GuzzleHttp in C:AppServwwwgooglevendorgoogleapiclientsrcGoogleHttpREST.php on

  11. I copied the exact same code but I was getting the following error:
    raise HttpError(resp, content, uri=self.uri)

    googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/upload/drive/v3/files?alt=json&uploadType=multipart returned "Insufficient Permission: Request had insufficient authentication scopes.">

    What should I do to fix it?

Leave a Reply

Your email address will not be published. Required fields are marked *