使用云端硬盘文件流获取Google云端硬盘文件链接 [英] Get Google Drive files links using Drive File Stream

查看:110
本文介绍了使用云端硬盘文件流获取Google云端硬盘文件链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用云端硬盘文件流来访问我的Google云端硬盘文件.
因此,我有了所有使用Python的Google Drive文件的列表(使用 os.path.walk ),但我想知道是否可以在线获取文件链接.
我在Mac OS X上并使用Finder,并单击第二次单击,我有一个选项使用Google云端硬盘打开",可直接在浏览器中打开文件.我想对我的所有文件自动执行相同的操作.

I am using Drive File Stream to access to my Google Drive files.
So I have the list of all my Google Drive files in Python (using os.path.walk) but I want to know if it's possible to get the file online link.
I am on Mac OS X and using Finder, with the secondary click, I have an option "Open with Google Drive" which directly open the file on my browser. I want to automatically do the same thing with all my files.

推荐答案

我最近发现了一种更有效的方法,用于检索Google Drive File Stream文件系统中任何给定文件/文件夹的Drive API'文件ID'.尽管我在Windows系统上发现了此功能,但Mac OS X上可能有类似的功能.

I recently discovered a much more efficient way of retrieving the Drive API 'File ID' of any given file/folder located within your Google Drive File Stream file system. Although I found this functionality on a Windows system, there may be similar functionality on Mac OS X.

我不知道到底有什么机制允许以下功能,但其功能与NTFS备用数据流的工作方式几乎相同.问题是,驱动器文件流的虚拟驱动器的属性显示它已被分区为FAT32,不支持备用数据流.也许Google的文件系统驱动程序只是在模仿NTFS备用数据流的行为.无论如何,驱动器文件流驱动程序添加了一种机制,用于读取附加到位于其文件系统内的文件/文件夹的特殊元数据.可以通过在任何后缀有冒号的文件/文件夹路径上调用"ReadFile"来访问此元数据,后跟一个特殊的标识符,该标识符描述了要检索的元数据.这些是我到目前为止发现的标识符(包括其中的一些描述):

I do not know exactly what mechanism allows for the functionality described below, but it is nearly identical in function to the way NTFS alternate data streams work. The thing is, the properties of Drive File Stream's virtual drive show it as being partitioned as FAT32 which do not support alternate data streams. Perhaps Google's file system driver is simply emulating the behavior of NTFS alternate data streams. Regardless, the Drive File Stream driver adds a mechanism for reading special metadata attached to file/folder's located within its file system. This metadata can be accessed by calling 'ReadFile' on any file/folder path that is suffixed with a colon followed by a special identifier describing the metadata one wants to retrieve. These are the identifiers I've discovered so far (including descriptions for some of them):

  • user.drive.id -文件/文件夹的驱动器API文件ID"
  • user.drive.team_drive_id -文件/文件夹的驱动器API"Team Drive ID"(如果不在Team Drive中,则为空)
  • user.drive.gdoc -如果文件是"Google Docs"文档,则返回"1";如果不是,则返回"0"
  • user.drive.email -据我所知,这只是返回已登录Drive File Stream的Google帐户的电子邮件地址(我尝试在归另一个Google帐户所有,但它仍返回了我的电子邮件地址)
  • user.drive.itemprotostr -提供几乎所有附加到文件的元数据,包括几乎所有这些其他标识符的输出
  • user.drive.md5 -文件的MD5校验和
  • com.apple.FinderInfo -不知道这是否是有效的标识符(因为它在Windows上不起作用),但是由于我发现它与其他标识符非常接近,所以可能与您的平台有关,我想我会提供以防万一
  • user.drive.stableid
  • user.drive.pinned
  • user.drive.uncommitted
  • user.drive.progress
  • user.drive.impression
  • user.drive.is_virtual_folder
  • user.drive.thumbnail
  • user.drive.id - Drive API 'File ID' of the file/folder
  • user.drive.team_drive_id - Drive API 'Team Drive ID' of the file/folder (empty if not in a Team Drive)
  • user.drive.gdoc - Returns '1' if the file is a 'Google Docs' document or '0' if it is not
  • user.drive.email - As far as I can tell, this simply returns the email address of the Google account that Drive File Stream is signed into (I tried calling this on a file that is owned by another Google account, but it still returned my email address)
  • user.drive.itemprotostr - Provides nearly all of the metadata attached to the file, including the output of nearly all of these other identifiers
  • user.drive.md5 - The MD5 checksum of the file
  • com.apple.FinderInfo - Not sure if this actually a valid identifier (as it does not work on Windows), but since I found it in close proximity to the others, and it may be relevant to your platform, I thought I would provide it just in case
  • user.drive.stableid
  • user.drive.pinned
  • user.drive.uncommitted
  • user.drive.progress
  • user.drive.impression
  • user.drive.is_virtual_folder
  • user.drive.thumbnail

在Windows上,从命令行读取此元数据的一种简单方法是使用"type"命令.以下示例将为您提供位于Google云端硬盘根目录中的文件"test.txt"的云端硬盘API文件ID:

On Windows, an easy way to read this metadata from the command line is by using the 'type' command. The following example would give you the Drive API file ID of the file 'test.txt' residing in the root directory of your Google Drive:

type "G:\My Drive\test.txt:user.drive.id"

注意:如果在某种类型的脚本中使用此脚本来创建新文件/文件夹并在之后快速读取"user.drive.id",请注意,真实"文件ID可能需要花费几秒钟的时间被生成.如果您读取'user.drive.id'的值并且它以'local'开头,则意味着它尚未生成实际的文件ID.我认为,处理此问题的最佳方法是创建一个在检查之间休眠的异步循环,然后在不再以本地"开头时返回文件ID.

Note: If you are using this in some type of script that is creating new files/folders and quickly reading the 'user.drive.id' afterwards, be aware that it can take many seconds for the "real" file id to be generated. If you read the value of 'user.drive.id' and it starts with 'local', this means that it has not yet generated an actual file id. In my opinion, the best way to deal with this is to create an asynchronous loop that sleeps between checks, and then returns the file id once it no longer starts with 'local'.

我个人不使用Mac,因此我绝对不是最有资格提供有关Mac使用建议的人.话虽这么说,我确实对Linux有一定的经验,并且我相信OS X使用很多相同的命令,因为它是基于Unix的.如果Windows功能直接与OS X相关(我不确定),那么我相信以下命令应该可以实现与上面提供的Windows命令相同的功能:

I do not personally use Mac, so I'm definitely not the most qualified individual to offer advice on its use. With that being said, I do have a bit of experience in Linux, and I believe OS X uses a lot of the same commands since it is Unix based. If the Windows functionality directly correlates to OS X (which I am not at all sure of), I believe the following command should achieve the same thing as the Windows command provided above:

cat "/Volumes/GoogleDrive/My Drive/test.txt:user.drive.id"

我希望此信息对您或可能遇到此问题的任何其他人有用.我知道这对于我的Python应用程序非常有价值,因为它允许我使用已经由Drive File Stream缓存的数据,而不必为每个单独的文件进行单独的API调用(在我的情况下为十万个).祝您的项目好运!

I hope this info is useful to you or anyone else who might come across this. I know it was very valuable for my Python app, as it allowed me to use data that was already cached by Drive File Stream rather than having to make a separate API call for each individual file (which in my case was 10's of thousands). Good luck with your project!

这篇关于使用云端硬盘文件流获取Google云端硬盘文件链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆