有没有办法通过c#获取我在谷歌驱动器上传的文件/文件夹#

时间:2018-02-23 12:14:47

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

我正在使用C#中的Google云端硬盘API。我一直在研究file.list方法。

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

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

try {
            StringRequest stringRequest = new StringRequest(Request.Method.POST, URL,
                    new Response.Listener<String>() {
                        @Override
                        public void onResponse(String response) {
                            progressDialog.dismiss();
                            System.out.println("Response is : " + response);
                            try {
                                JSONObject jsonLogin = new JSONObject(response);
                                if (jsonLogin.getInt("status") == 1) {

                                } else {
                                    Toast.makeText(getActivity(), jsonLogin.getString("MSG"), Toast.LENGTH_LONG).show();
                                }
                            } catch (Exception ex) {
                                System.out.println("EXCEPTION IN SUCCESS OF LOGIN REQUEST : " + ex.toString());
                            }
                        }
                    },
                    new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            progressDialog.dismiss();
                            System.out.println("ERROR IN LOGIN STRING REQUEST : " + error.getMessage());
                        }
                    }) {
                @Override
                protected Map<String, String> getParams() {
                    Map<String, String> params = new HashMap<String, String>();
                    params.put("USERID", "US-485212391");
                    return params;
                }

            };

            RequestQueue requestQueue = Volley.newRequestQueue(getActivity());
            requestQueue.add(stringRequest);
            progressDialog = new ProgressDialog(getActivity());
            progressDialog.setMessage("LoggingIn...");
            progressDialog.show();
        } catch (Exception ex) {
            System.out.println(" Exception : " + ex);

        }

1 个答案:

答案 0 :(得分:1)

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

发送像这样的搜索

  

mimeType =&#39; application / vnd.google-apps.folder&#39;和title =&#39;你好&#39;

以下代码应显示如何使用参数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);
        }
    }

至于你的第一个问题,我仍然试图让搜索只返回你创建的文件。我可以选择由不接缝创建的拥有者。仍在尝试

更新

由于只有创建时间,因此无法创建。我能做的最好的事情就是找到你拥有的文件,我想如果你创建了它。但是,如果您在创建后将所有权转让给其他人,那么您就不会知道。

'me' in owners