FoxPro Programming
How to get a list of files in a Google Drive folder
Gravatar is a globally recognized avatar based on your email address. How to get a list of files in a Google Drive folder
  Russell Campbell
  All
  Apr 11, 2022 @ 04:52pm

I'm looking around for the easiest way to retrieve a list of files from a shared folder on a Google Drive. Then, of course, I want to download the files. It seems I could create a WW HTTP object and use a bit of Javascript and then maybe get the list in that fashion, but I'm not sure about the downloading part. There's Google.Apis.Drive.v2.dll that is for .NET, though I'm not sure why VFP couldn't use it since it's a DLL (or, if there is a limitation, then maybe VFP and .NET Interop could be employed). I'm still casting about, but thought I'd go ahead and post here.

Gravatar is a globally recognized avatar based on your email address. re: How to get a list of files in a Google Drive folder
  Rick Strahl
  Russell Campbell
  Apr 12, 2022 @ 02:13pm

Google should have a REST API that you can access to get at your files. You'll need an API Key to do this.

If this is a desktop application, you can just access the Windows shared folder and read and write in those directories directly.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: How to get a list of files in a Google Drive folder
  Russell Campbell
  Rick Strahl
  Apr 12, 2022 @ 03:30pm

Thanks, Rick. Yeah, sorry, I should have realized I was not providing enough info. I have a client where the program I wrote for them runs on thousands of their customers' computers. We're using a Google folder to provide some update files. The users can go to the folder and download the files, drop them in the right place, and then the program can process them. However, I was looking to make this more automatic and have the program recognize new update files, get them, and then process them. And it's not really realistic to expect every customer to be installing the Google Drive software that would let them see the contents of this folder as if it were a Windows folder. I'm just not finding any examples of accessing the contents of a Google Drive folder (when you can't just treat it like a Windows folder) from a VFP app. I hope I haven't been as clear as mud again.

Gravatar is a globally recognized avatar based on your email address. re: How to get a list of files in a Google Drive folder
  Rick Strahl
  Russell Campbell
  Apr 12, 2022 @ 03:42pm

You can use the API to access the folder using a single account and then exposing the files as needed - the problem with that is keeping the API key secret so the account isn't compromised. Otherwise each user has to provide their Google Service keys.

If you're going to go down this path though I'd recommend you use something else, like the Google equivalent of Azure Blob storage or some other plain storage mechanism that isn't tied to a specific account, but is a generic service that you access with an access key. Same issue but it's then isolated to that specific storage account as opposed to exposing an entire account.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: How to get a list of files in a Google Drive folder
  Russell Campbell
  Rick Strahl
  Apr 14, 2022 @ 01:38pm

Ok, let me make sure we're on the same page now. We're talking about my client's Google Drive and they have created the folder for the update files and their customers are going to this folder to get update files (or will be). I'm just trying to automate this so that the user can't screw anything up and generate customer support calls. Does what you were saying apply to such a folder (I think it's just set up as an "anyone with the link can view the files" type of folder)? And I need to determine what "view" means - can they download? I assume so. There's certainly not much value in viewing a list of files that you then can't do anything with. Anyway, I'm not sure why anyone would need to provide Google Service Keys to access such a folder. Thanks again for your replies.

Gravatar is a globally recognized avatar based on your email address. re: How to get a list of files in a Google Drive folder
  Rick Strahl
  Russell Campbell
  Apr 14, 2022 @ 03:45pm

If your client is using Google Drive, they almost certainly will have the Google Drive extension installed so you can count on whatever mapping is in:

c:\users\<username>\GoogleDrive

Assuming they have approved the shared drive it'll show up as a folder there. The key part is probably going to be how you can identify the folder correctly - you probably will have to scan the entire folder hierarchy and search each directory name for some token that you can identify for your application.

Using file folders is by far the easiest way to access and share data as you're just using standard file APIs and Google Drive handles the syncing of the files to the cloud and other machines. If you use the API, you'll have to deal with oAuth authentication, API keys, and if you use the API a large API library distribution etc. (but you can probably just use the REST API to avoid the local footprint).

For file folders, file permissions should reflect the access settings in Google Drive. If you don't have read access you can't see the file, if you don't have write access you can't write it etc. It all pretty much works as expected, but it's mapped onto the file system semantics. There are more things that you can do with the API (such as assigning rights - remapping etc.) but the core access is supported through just the file system.

I'm assuming this works the same with GDrive as with DropBox and OneDrive which are the ones I use.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: How to get a list of files in a Google Drive folder
  Russell Campbell
  Rick Strahl
  Apr 14, 2022 @ 04:36pm

Rick, I apologize for continuing to be confused about whether we're on the same page, but please bear with me. Your answer makes me think we aren't. My client will have the update files on their Google Drive. Their customers, thousands of them spread out across the US, have no connection to my client's Google Drive folder other than the URL. My client is not going to be asking them to install the Google Drive software that could (as I understand it) allow them to see that folder with a drive mapping in Windows. My VFP program runs on all these computers spread out across the US. So it needs to be able to see what's in that Google Drive folder and download any new update files without the benefit of a Windows mapped drive. I think it'd be wonderful if I could DECLARE a DLL and give it the folder's URL and it would supply me with a list of files so that I could see what this particular installation has already downloaded and applied and what might be newly available. Then I could say "get these files for me" and then I could just use them after that DLL had downloaded them. That seems useful, but I haven't found that so far. Google talks about a DLL but acts like it's specific to certain languages, which is certainly not what I'm used to (and maybe the DLL doesn't even do what I want). So if I have to access the folder via some "over the Internet" call, then I'm just trying to figure out the best (easiest) way to do that.

© 1996-2022