I want to download files via the browser from Google Drive. I am able to access the files' data and details, via drive.get but I am not able to export the files. I didn't see a binaryString in the response.
Then I got in the touch with the API-Explore, where I'm not able to download anything too. Any ideas/hints?
SCOPES
: 'https://www.googleapis.com/auth/drive'API Key
at the Credentials PageOAuth 2.0 Client IDs
Public hello world doc helloWorld
mimeType:'application/vnd.google-apps.document'
id:'1O2ORp9te3FzqTFZkPLGNGvAnzcKBhdGZ-lu8TgABPrY'
{
"error": {
"errors": [
{
"domain": "global",
"reason": "badRequest",
"message": "The requested conversion is not supported.",
"locationType": "parameter",
"location": "convertTo"
}
],
"code": 400,
"message": "The requested conversion is not supported."
}
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<script type="text/javascript">
var developerKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
var clientId = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
var appId = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
var scope = 'https://www.googleapis.com/auth/drive.drive'
const mimeType = 'application/vnd.google-apps.document'
const fileID = '1O2ORp9te3FzqTFZkPLGNGvAnzcKBhdGZ-lu8TgABPrY'
function load() {
gapi.load('client:auth2', () => {
console.log(gapi)
gapi.client
.init({
clientId,
scope,
apiKey: developerKey,
discoveryDocs: ['https://www.googleapis.com/discovery/v1/apis/drive/v3/rest'],
})
.then(
() => {
gapi.auth2.getAuthInstance().signIn()
gapi.client.load('drive', 'v3', () => {
gapi.client.drive.files
.export({
fileID,
mimeType,
})
.then(res => console.log(res))
.catch(error => console.error(error))
})
},
error => console.error(error)
)
})
}
</script>
</head>
<body>
<div id="result"></div>
<script type="text/javascript" src="https://apis.google.com/js/api.js?onload=load"></script>
</body>
</html>
When I saw your question, I noticed that the file you want to export is Google Document and the mimeType you want to export is application/vnd.google-apps.document
. At Google Drive, unfortunately, in the current stage, Google Docs files cannot be directly exported as the original mimeType of Google Docs. For example, Google Document cannot be exported as Google Document. By this, an error of The requested conversion is not supported.
is returned. In this case, it is required to convert it to other type. For example, it's DOCX file, PDF, and so on. It seems that this is the current specification at the Google side.
From the above situation, in order to remove the current issue of your situation, how about the following modification?
mimeType:'application/vnd.google-apps.document'
const mimeType = 'application/vnd.google-apps.document'
mimeType:'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
const mimeType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
and
mimeType:'application/pdf'
const mimeType = 'application/pdf'
When you want to know the mimeTypes that Google Document can be exported, you can achieve this using the method of "About: get" in Drive API. Ref When the value of exportFormats
of Google Document is retrieved, it is as follows.
[
"application/rtf",
"application/vnd.oasis.opendocument.text",
"text/html",
"application/pdf",
"application/epub+zip",
"application/zip",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"text/plain"
]