我无法识别用户云端硬盘的根文件夹。对于英语用户,它被命名为“我的驱动器”,但对于法国用户,它被命名为“Mon Drive”。文件ID对于所有根文件夹都是唯一的,因此无法使用此属性。
如何从metadata api的响应中确定一个文件夹是否是用户驱动器的根文件夹?
答案 0 :(得分:0)
如果有人与您共享尚未添加到自己的驱动器的文件夹,则您可能没有文件夹的父ID。基本上,“与我共享”文件夹没有父ID。
您可以执行GET获取根文件夹的详细信息。
GET https://www.googleapis.com/drive/v2/files/root
请记住在此URL的末尾直接提及 root 。这是您的根文件夹的别名。您应该得到一个JSOn响应,其中您应该具有根文件夹的“ id”。
答案 1 :(得分:-1)
这是一个尝试的链接: https://developers.google.com/drive/v2/reference/files/get#try-it
我提供的文件ID不在根目录中。注意:我们可以从 - >获取fileId 右键单击文件>获得可共享的链接>>有id = {*** fileId * } **
我提供了我的fileId,它使用以下JSON输出执行,您可以在其中看到isRoot:false. /* It means that file holding directory is not root directory */
json格式的输出结果:
{
"kind": "drive#file",
"id": "0B-loIMZmVFUXZXJDRjM5cjhhNmM",
"etag": "\"ZAMbZ9abHBEg72qh6Q2B0zjcjMA/MTUwMDg3NzA3ODA0MQ\"",
"selfLink": "https://www.googleapis.com/drive/v2/files/0B-loIMZmVFUXZXJDRjM5cjhhNmM",
"webContentLink": "https://drive.google.com/uc?id=0B-loIMZmVFUXZXJDRjM5cjhhNmM&export=download",
"alternateLink": "https://drive.google.com/file/d/0B-loIMZmVFUXZXJDRjM5cjhhNmM/view?usp=drivesdk",
"embedLink": "https://drive.google.com/file/d/0B-loIMZmVFUXZXJDRjM5cjhhNmM/preview?usp=drivesdk",
"iconLink": "https://drive-thirdparty.googleusercontent.com/16/type/video/mpeg",
"thumbnailLink": "https://lh5.googleusercontent.com/1VGXZZ-keO9yO5P5eYkUWrKXNsi9dG80zGQHlSRr4usJn_AAWGL-prXhoSeBV_XwXKqzQQ=s220",
"title": "VTS_01_1.VOB",
"mimeType": "video/mpeg",
"labels": {
"starred": false,
"hidden": false,
"trashed": false,
"restricted": false,
"viewed": true
},
"createdDate": "2017-07-11T00:58:46.342Z",
"modifiedDate": "2017-07-24T06:17:58.041Z",
"modifiedByMeDate": "2017-07-24T06:17:58.041Z",
"lastViewedByMeDate": "2017-07-24T06:18:20.076Z",
"markedViewedByMeDate": "1970-01-01T00:00:00.000Z",
"version": "677073",
"parents": [
{
"kind": "drive#parentReference",
"id": "0B-loIMZmVFUXYjFpTnNpWXM5U0k",
"selfLink": "https://www.googleapis.com/drive/v2/files/0B-loIMZmVFUXZXJDRjM5cjhhNmM/parents/0B-loIMZmVFUXYjFpTnNpWXM5U0k",
"parentLink": "https://www.googleapis.com/drive/v2/files/0B-loIMZmVFUXYjFpTnNpWXM5U0k",
"isRoot": false
}
],
"downloadUrl": "https://doc-0k-48-docs.googleusercontent.com/docs/securesc/bculidesqdf6868f2kpe9ck7n2ek7rik/tf0bp5qc9adb3l2nvq8224jlefl11mbl/1500876000000/00155113073667341356/00155113073667341356/0B-loIMZmVFUXZXJDRjM5cjhhNmM?e=download&gd=true",
"userPermission": {
"kind": "drive#permission",
"etag": "\"ZAMbZ9abHBEg72qh6Q2B0zjcjMA/sYdDjsCbpl5sdrQ1oJnGyZ0gu5M\"",
"id": "me",
"selfLink": "https://www.googleapis.com/drive/v2/files/0B-loIMZmVFUXZXJDRjM5cjhhNmM/permissions/me",
"role": "owner",
"type": "user"
},
"originalFilename": "VTS_01_1.VOB",
"fileExtension": "VOB",
"md5Checksum": "5328c8049ca351743ac7f30af1c242f6",
"fileSize": "389033984",
"quotaBytesUsed": "389033984",
"ownerNames": [
"Uddhav Gautam"
],
"owners": [
{
"kind": "drive#user",
"displayName": "Uddhav Gautam",
"picture": {
"url": "https://lh3.googleusercontent.com/-UoxeYRihw94/AAAAAAAAAAI/AAAAAAAAFBQ/GY5GOL_IGwU/s64/photo.jpg"
},
"isAuthenticatedUser": true,
"permissionId": "00155113073667341356",
"emailAddress": "infofuniversities@gmail.com"
}
],
"lastModifyingUserName": "Uddhav Gautam",
"lastModifyingUser": {
"kind": "drive#user",
"displayName": "Uddhav Gautam",
"picture": {
"url": "https://lh3.googleusercontent.com/-UoxeYRihw94/AAAAAAAAAAI/AAAAAAAAFBQ/GY5GOL_IGwU/s64/photo.jpg"
},
"isAuthenticatedUser": true,
"permissionId": "00155113073667341356",
"emailAddress": "infofuniversities@gmail.com"
},
"capabilities": {
"canCopy": true,
"canEdit": true
},
"editable": true,
"copyable": true,
"writersCanShare": true,
"shared": true,
"explicitlyTrashed": false,
"appDataContents": false,
"headRevisionId": "0B-loIMZmVFUXWmFnM0Q2YnpDaGphc0lPMXNNZ1JYc2JpdllBPQ",
"videoMediaMetadata": {
"width": 720,
"height": 480,
"durationMillis": "494631"
},
"spaces": [
"drive"
]
}
如果您想知道目录是否是根目录?你可以简单地使用
if(yourDirectory.getParents().size() > 0) { /* your directory can't be root here. Root directory has no parent directory */ }