When using the Google Picker, what does the .setDocument(document) do/used for?

Viewed 84

Context: The feature I am working on is exporting user data into a Google Document that appears exactly as the PDF version we export but allows for easier editing. Because this file has a lot of complex tables I created a template document, that is public to everyone with viewer access via link, that contains the all the potential tables needed with formatting/styling that are then programmatically adjusted or outright deleted as needed. This currently works by copying the file to the users drive and then taking the file id from the response to use the Docs API to fill it with data using the .../auth/drive scope.

I have been developing an alternative flow for our app so we can avoid using the permissive, restricted scope .../auth.drive and instead uses the .../auth/drive.file and .../auth/drive.metadata scopes and the Google Picker. This tries the initial flow and then, if the app recieves a 403 "user has not granted app APP_NUMBER_HERE access to file _FILE_ID_HERE" error, their is a dialog that describes the user needs to follow a link to view the file (and this allows them to access it from their drive) and then if they follow the link pops the Google Picker and requests they select that file.

Everything works decently well but the documentation mentions a function .setDocument(document) for the google.picker.PickerBuilder() that doesn't have much documentation or examples (link to picker builder section in documentation: https://developers.google.com/picker/docs/reference#picker-builder). It sounds like it could allow me to be set the specific for them to choose however I cannot get it working or know how to use it correctly.

I have tried to test it when building the picker object like:

var picker = new google.picker.PickerBuilder()
    .addView(google.picker.ViewId.DOCUMENTS)
    .setTitle("Please pick the <fileName> file")
    // .setDocument(document) // this breaks the entire picker, creating a undefined object
    .setAppId(appID)
    .setOAuthToken(token)
    .setDeveloperKey(devKey)
    .setCallback(filePickerCallback)
    .build();
  picker.setVisible(true);

Note for the "document" I have tried using the document ID, and a URL of the document as well, but it breaks the picker every time.

Does anyone know what the setDocument function is for? Or how to use it correctly?

1 Answers

Since gapi is a closed-source product, the official and correct answer can be achieved only by asking Google.

One thing I know is, DefinitelyTyped has type definitions for the Google Picker API, which you can use by:

npm i -D @types/google.picker

According to this definition, setDocument takes an argument of type Document i.e. document as in document.write. This suggests this function is not something you are looking for.

Related