文件何时从 Google 云端硬盘服务帐户中删除?
When does the files get deleted from Google Drive Service account?
我想知道 google 云端硬盘服务帐户中的文件会保留多长时间?
我找不到它的默认到期时间。由于我无法控制该帐户,我怎么知道文件已被删除,或者如果没有办法,我是否必须自己从服务帐户中删除文件?
由于您无法控制该帐户,我不知道您如何才能真正删除该帐户拥有的文件。只要所有者不删除文件,该文件就会保留在那里。
https://support.google.com/drive/answer/2375102
Put a file in trash
To remove a file from your Drive, you can put it
in your trash. Your file will stay there until you empty your trash.
If you're the owner of the file, others can view it until you
permanently delete the file. If you're not the owner, others can see
the file even if you empty your trash.
这与用户创建文件的方式相同(无到期日期)。要了解任何更改(如删除),您可以查看 Change Feed to retrieve the changes.
Changes: list
- Lists the changes for a user.
Detect Changes
- For Google Drive apps that need to keep track of changes to files, the Changes collection provides an efficient way to detect changes to all files, including those that have been shared with a user. The collection works by providing the current state of each file, if and only if the file has changed since a given point in time.
您可以使用服务帐户删除文件,因为它是文件的所有者。您还可以查看此 SO question 关于如何检查 file/folder 是否被删除。
文件会一直保留到您自己删除它们为止。
您始终可以从 google 驱动器 API(我使用 V3)获取文件列表并获取文件列表及其 ID 并删除任何您想要的。您还不能通过 Web 界面执行此操作。
下面是一个关于如何获取文件列表的 C# 示例:
public List<Google.Apis.Drive.v3.Data.File> GetFilesList(string SearchQ = null)
{
List<Google.Apis.Drive.v3.Data.File> ListOfFiles = new List<Google.Apis.Drive.v3.Data.File>();
FilesResource.ListRequest listRequest = _CurrentDriveService.Files.List();
listRequest.PageSize = 1000;
if (SearchQ != null)
{
listRequest.Q = SearchQ; //("'PARENT_ID' in parents");
}
listRequest.Fields = "nextPageToken, files(id, name,parents,mimeType,size,capabilities,modifiedTime,webViewLink,webContentLink)";
FileList fileFeedList = listRequest.Execute();
while (fileFeedList != null)
{
foreach (File file in fileFeedList.Files)
{
ListOfFiles.Add(file);
}
if (fileFeedList.NextPageToken == null)
{
break;
}
listRequest.PageToken = fileFeedList.NextPageToken;
fileFeedList = listRequest.Execute();
}
return ListOfFiles;
}
以及如何删除特定文件:
public bool DeleteFileFromDrive(string FileID) // only to be used when you are the owner of the file. Otherwise it will have no effect.
{
try
{
FilesResource.GetRequest gr = new FilesResource.GetRequest(_CurrentDriveService, FileID);
var FileData = gr.Execute();
if (FileData.MimeType == GoogleDriveMimeTypes.GetFolderMimeTypeString())
{
var filesInFolder = GetFilesList("'" + FileID + "' in parents");
if (filesInFolder.Count > 0)
{
// directory is not empty
return false;
}
}
var requestD = _CurrentDriveService.Files.Delete(FileID);
requestD.Execute();
return true;
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
return false;
}
}
我发现如果您使用 API 从服务帐户中删除该文件(并且因为服务帐户是该文件的所有者),它将从该文件的所有共享驱动器部分中删除访问该文件的用户。感谢@some1、@MrRebot 和@Hadar Ben David 帮助我得出这个结论。
我想知道 google 云端硬盘服务帐户中的文件会保留多长时间?
我找不到它的默认到期时间。由于我无法控制该帐户,我怎么知道文件已被删除,或者如果没有办法,我是否必须自己从服务帐户中删除文件?
由于您无法控制该帐户,我不知道您如何才能真正删除该帐户拥有的文件。只要所有者不删除文件,该文件就会保留在那里。
https://support.google.com/drive/answer/2375102
Put a file in trash
To remove a file from your Drive, you can put it in your trash. Your file will stay there until you empty your trash.
If you're the owner of the file, others can view it until you permanently delete the file. If you're not the owner, others can see the file even if you empty your trash.
这与用户创建文件的方式相同(无到期日期)。要了解任何更改(如删除),您可以查看 Change Feed to retrieve the changes.
Changes: list
- Lists the changes for a user.
Detect Changes
- For Google Drive apps that need to keep track of changes to files, the Changes collection provides an efficient way to detect changes to all files, including those that have been shared with a user. The collection works by providing the current state of each file, if and only if the file has changed since a given point in time.
您可以使用服务帐户删除文件,因为它是文件的所有者。您还可以查看此 SO question 关于如何检查 file/folder 是否被删除。
文件会一直保留到您自己删除它们为止。 您始终可以从 google 驱动器 API(我使用 V3)获取文件列表并获取文件列表及其 ID 并删除任何您想要的。您还不能通过 Web 界面执行此操作。
下面是一个关于如何获取文件列表的 C# 示例:
public List<Google.Apis.Drive.v3.Data.File> GetFilesList(string SearchQ = null)
{
List<Google.Apis.Drive.v3.Data.File> ListOfFiles = new List<Google.Apis.Drive.v3.Data.File>();
FilesResource.ListRequest listRequest = _CurrentDriveService.Files.List();
listRequest.PageSize = 1000;
if (SearchQ != null)
{
listRequest.Q = SearchQ; //("'PARENT_ID' in parents");
}
listRequest.Fields = "nextPageToken, files(id, name,parents,mimeType,size,capabilities,modifiedTime,webViewLink,webContentLink)";
FileList fileFeedList = listRequest.Execute();
while (fileFeedList != null)
{
foreach (File file in fileFeedList.Files)
{
ListOfFiles.Add(file);
}
if (fileFeedList.NextPageToken == null)
{
break;
}
listRequest.PageToken = fileFeedList.NextPageToken;
fileFeedList = listRequest.Execute();
}
return ListOfFiles;
}
以及如何删除特定文件:
public bool DeleteFileFromDrive(string FileID) // only to be used when you are the owner of the file. Otherwise it will have no effect.
{
try
{
FilesResource.GetRequest gr = new FilesResource.GetRequest(_CurrentDriveService, FileID);
var FileData = gr.Execute();
if (FileData.MimeType == GoogleDriveMimeTypes.GetFolderMimeTypeString())
{
var filesInFolder = GetFilesList("'" + FileID + "' in parents");
if (filesInFolder.Count > 0)
{
// directory is not empty
return false;
}
}
var requestD = _CurrentDriveService.Files.Delete(FileID);
requestD.Execute();
return true;
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
return false;
}
}
我发现如果您使用 API 从服务帐户中删除该文件(并且因为服务帐户是该文件的所有者),它将从该文件的所有共享驱动器部分中删除访问该文件的用户。感谢@some1、@MrRebot 和@Hadar Ben David 帮助我得出这个结论。