Search code examples
google-apps-scriptgoogle-drive-api

Google App Script Advanced Service: Drive API


https://spreadsheet.dev/automatically-convert-excel-spreadsheets-to-google-sheets-using-apps-script

On the page above, Drive API is introduced to convert excel file to Google Sheet

  let blob = excelFile.getBlob();
  let config = {
    title: "[Google Sheets] " + excelFile.getName(),
    parents: [{id: excelFile.getParents().next().getId()}],
    mimeType: MimeType.GOOGLE_SHEETS
  };
  let spreadsheet = Drive.Files.insert(config, blob);

I've been checking Google Drive API's documentation and references, but couldn't find anything regarding Drive.Files and Drive.Files.insert. I am seeking the right documentation so I can learn to use these interfaces myself.


Solution

  • Unfortunately, it seems that the detailed document of Drive API of Advanced Google services is not been officially published. But, in your situation, I thought that the document at the autocomplete of the script editor of Google Apps Script might be useful.

    When the script editor of Google Apps Script is used, you can use the autocomplete of each method. In this case, when Drive API is enabled at Advanced Google services, this autocomplete can be also used for the methods of Drive API. When this is used, the documents of each method can be seen as follows. As a sample, Drive.Files.insert is used.

    enter image description here

    This completion includes an explanation of the method. In the case of Drive.Files.insert, it is found that it is Insert a new file. and the arguments are

    • resource: Drive_v2.Drive.V2.Schema.File
      • This is a request body of "Files: insert" of Drive API v2 Ref
    • mediaData: Blob
      • This is a Blob.
    • optionalArgs: Object
      • This is the query parameter of "Files: insert" of Drive API v2 Ref

    , respectively. From this, it is found that this is Drive API v2. And, Drive_v2.Drive.V2.Schema.File is returned. This can be seen at here.

    I thought that this document of the autocomplete with the script editor might be useful for understanding how to use Drive API at Advanced Google services.

    Note:

    • This autocomplete can be also used for all APIs (Sheets API, Docs API, and so on) of Advanced Google services. I think that the document shown with the autocomplete with the script editor might be useful for understanding how to use the APIs at Advanced Google services.

    References: