What mime types can I use to export a Google Sites, Google Forms, and Google Scripts using the Google Drive api?

Alistair Jones :

Using the list endpoint of the Google Drive api, I can retrieve the file ID and the mimetype of a Google Site file.

I tried to download the file and it fails. The response I get is "Only files with binary content can be downloaded. Use Export with Google Docs files." Makes sense.

Following the documentation here, I tired to export the file and it also fails. The response I get is:

com.google.api.client.http.HttpResponseException: 400 Bad Request
{
 "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."
 }
}

I tried it with the mimetype "application/pdf" and "application/zip" and "text/html" and still got the same response. What are the my export options here? I cannot find any documentation on this.

I'm having a similar problem with Google Form and Google Script files as well.

My Java code example:

Export export = driveService.files().export(fileId, "application/pdf");
export.executeMediaAndDownloadTo(outputStream);
Tanaike :

By the recent Google's update, the property of exportLinks was also added to Drive API v3. This property had been able to be used at only Drive API v2 before. By this update, the URLs for exporting the converted files of Google Docs can be retrieved using the files.get method of Drive API v3. The endpoint for this method is as follows.

Endpoint:

GET https://www.googleapis.com/drive/v3/files/{fileId}?fields=exportLinks
  • When it requests to this URL, the blob can be downloaded.
  • For example, the URL for exporting Spreadsheet as a PDF file is as follows.

    - https://docs.google.com/spreadsheets/export?id={fileId}&exportFormat=pdf
    
  • You can also directly create the exporting URL like above.

    • When you use this, if the Google Docs file is not publicly shared, please use the access token retrieved from OAuth2 and/or Service Account. If the file is publicly shared, you can download the file using API key.

Reference:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=142736&siteId=1