Google Drive Windows应用与/从fileId - 具有相同名称的项目以及多个父项 [英] Google Drive Windows App to/from fileId - items with same names, and multiple parents

查看:156
本文介绍了Google Drive Windows应用与/从fileId - 具有相同名称的项目以及多个父项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从网上的Google云端硬盘链接(也就是fileId)转换到硬盘上的Windows Google云端硬盘应用的路径,然后再返回。



如果API中存在某些内容(例如,产生一个不包含 C:\ Users \ [User] \Google Drive\ 从一个文件/文件夹ID,反之亦然),但没有。



到目前为止我做到了:


  1. Windows路径ID:获取路径的第一个文件夹并(从根开始)查找匹配的文件夹,然后重复,直到完成(可能带有文件名)。问题:项目可以被称为相同的东西,无论是文件或文件夹或两者的组合,这在Windows中很棘手。该应用程序添加了一个数字'(1)'等,我必须赶上,但我怎么知道哪个项目ID是正确的?我相信编号是基于日期,但我不确定。因此,我可能最终得到多个结果,并且无法确定哪个是哪个。


  2. ID到Windows路径:从文件/文件夹的名称该ID,然后继续添加父文件夹(S),直到我建立一个路径。问题:与上面的1相同,如果有多个匹配项目,那么在翻译到Windows时我无法知道应该使用哪个项目。问题:显然,Google云端硬盘中的商品可能有多个家长。不知道Windows应用程序如何工作。


任何人都可以帮助我调整自己的做法,我详细了解Google云端硬盘应用如何执行此操作?代码是受欢迎的,但不是必需的,我反过来可以提供我需要的代码。

如果我完全理解了这个问题,但是我仍然试图回答一个问题:



1 /假设您有Windows路径,


C:\ Users \User\Google Drive \myfile.ext



<您可以在GooDrive上创建一个类似路径的文件,迭代您的路径令牌
递归地在GooDrive上创建一个树结构。如果树节点(文件夹/文件)存在,则返回ID,否则创建对象。 GooDrive的主要区别在于标题查询可能会返回多个对象(文件夹/文件列表)。运气不好,您要么使用第一个,要么退出并出现错误。

  global path =C:\Users\ User\Google Drive\myfile.ext
createTree(String path){
rootFolderId =创建您的根目录或使用GooDrive root $ b $ fileId = iterate(firstToken(path,\ ),rootFolderId);


iterate(title,parentFolderId){
ID(或多个ID)=在parentFolderId中搜索标题

if(存在多个ID)
BOOM - 报告错误并退出或使用第一个

if(令牌不是最后一个){
if(存在标题的单个ID){
folderId =找到ID
} else {
folderId = createFolder with title和parentFolderId元数据
}
迭代(nextToken(path,\),folderId)

)else {(最后一个标记表示文件)
if(标题存在单个ID){
fileId = found ID
} else {
fileId = createFile with title和parentFolderId元数据
}
return fileId
}
}

你没有指定语言,但如果是Java,你可以看到类似的过程 here createTree()方法中(这是Android代码,所以在那里有很多Android特定的goo,对不起)假设你有一个Google Drive fileId ,你用这个伪代码构建Windows路径从下到上)。再次,你可能有多个父母,你必须处理(错误或多个路径与单个对象的链接)

= fileId的标题
$ b $ while(){
parentID =获取fileId的父母
$ b $ if(多个parentIDs存在)
BOOM - 报告错误并退出或构造如果(parentID无效或parentId的标题无效)
break

path = parentID的标题+\+路径

if(parentID的标题是您的根目录)
break
}

还有一件事:你说文件夹和文件可以被称为同一件事......

在GooDrive中,查看MIME类型,有一个特定的MIME类型application / vnd.google-apps.folder,告诉你它是一个文件夹。此外,任何parentId元数据都表示文件夹,因为文件不能是父母。


好运

I'm trying to translate from a Google Drive link on the web (well, the fileId anyway) to the Windows Google Drive app's path on the hard disk, and back again.

It would be helpful if there was something in the API for this (eg produce a path excluding the C:\Users\[User]\Google Drive\ from a file/folder ID, and vice versa), but there isn't.

So far I do:

  1. Windows Path to ID: get the first folder of the path and (starting from the root) look for a matching folder, then repeat until finished (possibly with a file name). PROBLEM: Items can be called the same thing, whether files or folders or combinations of both, which is tricky in Windows. The app adds a number ' (1)' and so on, which I have to catch, but how can I know which item ID is the correct one? I believe that numbering is based on date but I'm not sure. So I can potentially end up with multiple results and no way to tell which is which.

  2. ID to Windows Path: take the name of the file/folder from the ID, then keep adding the parent folder(s) until I build up a path. PROBLEM: same as 1 above, if there are multiple matching items then I can't tell which I should use when translating to Windows. PROBLEM: Apparently items in Google Drive can have more than one parent. Not sure how that works in the Windows app.

Can anyone help me fine tune how I do this, or tell me the exact details of how the Google Drive app does it? Code is welcome but not required, and I in turn can provide the code I use if needed.

解决方案

I'm not sure if I fully understand the question, but I try to smack an answer anyway:

1/ assuming you have a Windows path,

C:\Users\User\Google Drive\myfile.ext

you create a file with a similar path on GooDrive iterating your path's tokens recursively creating a tree structure on GooDrive. If the tree nodes (folders/files) exist, return ID's, otherwise create the objects. The main difference in GooDrive is that title query may return multiple objects (list of folders/files). Bad luck, you either use the first one or quit with an error.

  global path = "C:\Users\User\Google Drive\myfile.ext"
  createTree(String path) {
    rootFolderId = create your root or use GooDrive root
    fileId = iterate (firstToken(path, "\"), rootFolderId);
  } 

  iterate(title, parentFolderId) {
    ID (or multiple IDs) = search for title in parentFolderId

    if (multiple IDs exist) 
      BOOM - report error and quit or use the first one

    if (token not last) {
      if (single ID for title exists) {
        folderId = found ID
      } else {  
        folderId = createFolder with title and parentFolderId metadata
      }
      iterate(nextToken(path, "\"), folderId)

    } else {   (last token represent file)
      if (single ID for title exists) {
        fileId = found ID
      } else {  
        fileId = createFile with title and parentFolderId metadata
      }
      return fileId    
    }
  }

You did not specify the language, but in case it is Java, you can see similar procedure here in the createTree() method (it is Android code, so there is a lot of Android specific goo there, sorry)

2/ assuming you have a Google Drive fileId, you construct the Windows path with this pseudocode (going from bottom up to the root). Again, you may have multiple parents you have to deal with (error or multiple paths with links to a single object)

  String path = fileId's title

  while () {
    parentID  = get fileId's parent

    if (multiple parentIDs exist) 
      BOOM - report error and quit or construct multiple paths
      (multiple paths would represent file/folder links)

    if (parentID not valid or parentId's title not valid)
      break

    path = parentID's title + "\" + path

     if (parentID's title is your root)
      break
  } 

One more thing: You say "Folders and files can be called the same thing..."
In GooDrive, look at the MIME type, there is a specific MIME type "application/vnd.google-apps.folder" that tells you it is a folder. Also, any parentId metadata represents folder, since files can't be parents.

Good Luck

这篇关于Google Drive Windows应用与/从fileId - 具有相同名称的项目以及多个父项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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