google-drive-sync icon indicating copy to clipboard operation
google-drive-sync copied to clipboard

GDrive File Scope implementation with file picker

Open Hoffs opened this issue 4 years ago • 1 comments

As per #42 I finally got around trying to implement this. As per my testing everything more or less works and the file scope seems to work as expected, only giving files that were picked. Adding this bit to somewhere will print out only 1 or how many files were picked.

var available = service.Files.List();
available.Fields = "files(id,name)";
var result = await available.ExecuteAsync();
foreach (var item in result.Files)
{
    Log.Info("Got {0}/{1}", item.Id, item.Name);
}

Some difficult parts:

  • Needs API Key, as explained in https://developers.google.com/picker/docs#appreg API key has to be provided when file picker is created, so that would mean that it would either be patched it when page is being served on baked in when plugin is being built.
  • Having the local web server serve up the page. The problem is that file picker only allows web application oauth2 app, so it is impossible to reuse desktop app token. With that it requires authorized javascript origin, which means that there has to be a set of ports whitelisted beforehand and it can't just get any random available port.

I don't expect this to be merged, a lot of parts are quite rough around the edges, data flow is a bit incorrect IMO at some parts, but it's a good POC that it's not that hard to use file scope. This should have no issues working with any other apps as long as they don't completely delete the file and upload new one in gdrive.

Hoffs avatar Sep 18 '21 08:09 Hoffs

Thanks for this. As discussed in #42, the proposed scheme faces significant challenges in a non-SAAS, open source platform project. But as you claim that it can be done, it should be seriously considered. When I get a chance I will look at the PR and I hope others interested in this will too.

walterpg avatar Sep 18 '21 23:09 walterpg