【问题标题】:Is there any way to get files/folders uploaded by me in google drive through c# [closed]有什么方法可以通过 c# 获取我在谷歌驱动器中上传的文件/文件夹[关闭]
【发布时间】:2018-02-23 12:14:46
【问题描述】:

我正在使用 C# 中的 Google 驱动器 API。我一直在看file.list方法。

我正在尝试列出我上传的文件夹/文件。以及基于文件夹名称的特定文件夹中的文件/文件夹。

到目前为止,我只能返回我所有文件的列表。

var request = service.Files.List().Execute();

【问题讨论】:

  • 欢迎来到 Stack Overflow。虽然这里有大量信息,但该站点不是代码编写服务。为了提高您的问题的质量,请出示您对此问题进行过哪些研究的证据,包括指向任何有用或听起来可能相关的任何页面的链接。请向我们展示您尝试过的任何代码以及您收到的结果的描述(包括任何错误消息的全文)。 Look here for tips on writing a good question
  • 请查看API documentation 尝试一下,如果您有更具体的问题,请回来。
  • 我已经浏览了api文档。在那里我根据父 ID 获取文件/文件夹,或者有什么方法可以根据文件夹名称获取 id?
  • @DaImTo 再看一遍,你是对的。

标签: c# google-api google-drive-api google-api-dotnet-client


【解决方案1】:

Files.list 有一个q 参数,可让您搜索文件。

发送这样的搜索

mimeType = 'application/vnd.google-apps.folder' 和 title = 'hello'

下面的代码应该告诉你如何使用参数code ripped from

public class FilesListOptionalParms
    {
        /// Comma-separated list of bodies of items (files/documents) to which the query applies. Supported bodies are 'user', 'domain', 'teamDrive' and 'allTeamDrives'. 'allTeamDrives' must be combined with 'user'; all other values must be used in isolation. Prefer 'user' or 'teamDrive' to 'allTeamDrives' for efficiency.
        public string Corpora { get; set; }  
        /// The source of files to list. Deprecated: use 'corpora' instead.
        public string Corpus { get; set; }  
        /// Whether Team Drive items should be included in results.
        public bool? IncludeTeamDriveItems { get; set; }  
        /// A comma-separated list of sort keys. Valid keys are 'createdTime', 'folder', 'modifiedByMeTime', 'modifiedTime', 'name', 'name_natural', 'quotaBytesUsed', 'recency', 'sharedWithMeTime', 'starred', and 'viewedByMeTime'. Each key sorts ascending by default, but may be reversed with the 'desc' modifier. Example usage: ?orderBy=folder,modifiedTime desc,name. Please note that there is a current limitation for users with approximately one million files in which the requested sort order is ignored.
        public string OrderBy { get; set; }  
        /// The maximum number of files to return per page. Partial or empty result pages are possible even before the end of the files list has been reached.
        public int? PageSize { get; set; }  
        /// The token for continuing a previous list request on the next page. This should be set to the value of 'nextPageToken' from the previous response.
        public string PageToken { get; set; }  
        /// A query for filtering the file results. See the "Search for Files" guide for supported syntax.
        public string Q { get; set; }  
        /// A comma-separated list of spaces to query within the corpus. Supported values are 'drive', 'appDataFolder' and 'photos'.
        public string Spaces { get; set; }  
        /// Whether the requesting application supports Team Drives.
        public bool? SupportsTeamDrives { get; set; }  
        /// ID of Team Drive to search.
        public string TeamDriveId { get; set; }  

    }

    /// <summary>
    /// Lists or searches files. 
    /// Documentation https://developers.google.com/drive/v3/reference/files/list
    /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
    /// </summary>
    /// <param name="service">Authenticated Drive service.</param>  
    /// <param name="optional">Optional paramaters.</param>
    /// <returns>FileListResponse</returns>
    public static FileList List(DriveService service, FilesListOptionalParms optional = null)
    {
        try
        {
            // Initial validation.
            if (service == null)
                throw new ArgumentNullException("service");

            // Building the initial request.
            var request = service.Files.List();

            // Applying optional parameters to the request.                
            request = (FilesResource.ListRequest)SampleHelpers.ApplyOptionalParms(request, optional);

            // Requesting data.
            return request.Execute();
        }
        catch (Exception ex)
        {
            throw new Exception("Request Files.List failed.", ex);
        }
    }

至于您的第一个问题,我仍在尝试让搜索仅返回您创建的文件。我可以选择由 dont seam 创建的那些。还在尝试

更新:

似乎没有办法被创造,因为只有一个创造的时间。我能做的最好的事情就是找到你拥有的文件,我猜如果你创建了它。但是,如果您在创建后将所有权转让给其他人,那么您就不会知道了。

'me' in owners

【讨论】:

    猜你喜欢
    • 2021-02-23
    • 2014-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多