get file content of google docs using google drive API v3

Solution 1

For v3 of the api, you can use the export method

Solution 2

You can also download files with binary content (non google drive file) in Drive using the webContentLink attribute of a file. From

A link for downloading the content of the file in a browser. This is only available for files with binary content in Drive.

An example (I use method get() to retrieve the webContentLink from my file):{
    fileId: id,
    fields: 'webContentLink'
    var webContentLink = success.result.webContentLink; //the link is in the success.result object
}, function(fail){
    console.log('Error '+ fail.result.error.message);

With google drive files, the export method can be used to get those files:
This method needs an object with 2 mandatory attributes (fileId, and mimeType) as parameters. A list of available mimeTypes can be seen here or here (thanks to @ravioli)

    'fileId' : id,
    'mimeType' : 'text/plain'
}, function(fail){
    console.log('Error '+ fail.result.error.message);

You can read non google doc file content (for example a text file) with with alt:"media". Official example. My example:

function readFile(fileId, callback) {
    var request ={
        fileId: fileId,
        alt: 'media'
    request.then(function(response) {
        console.log(response); //response.body contains the string value of the file
        if (typeof callback === "function") callback(response.body);
    }, function(error) {
    return request;

Solution 3

If you use files.export, you won't get any link that will let you download the file as stated in v3 Migration guide.

For example using the the try-it, I only got a MiMetype response but no downloadable link:

[application/vnd.oasis.opendocument.text data] 

Workaround for this is a direct download. Just replace FILE_ID with your Google Doc fileID and execute it in the browser. Through this, I was able to export Google docs files. 

Credits to labnol's guide for the workaround.

Author by


Updated on July 10, 2022


  • Admin
    Admin 28 days