Example #1
0
        public List <GoogleDriveFile> GetFolders(string driveID = "", bool trashed = false, bool writer = true)
        {
            if (!CheckAuthorization())
            {
                return(null);
            }

            string query = "mimeType = 'application/vnd.google-apps.folder'";

            if (!trashed)
            {
                query += " and trashed = false";
            }

            if (writer && string.IsNullOrEmpty(driveID))
            {
                query += " and 'me' in writers";
            }

            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("q", query);
            args.Add("fields", "nextPageToken,files(id,name,description)");
            if (!string.IsNullOrEmpty(driveID))
            {
                args.Add("driveId", driveID);
                args.Add("corpora", "drive");
                args.Add("supportsAllDrives", "true");
                args.Add("includeItemsFromAllDrives", "true");
            }

            List <GoogleDriveFile> folders = new List <GoogleDriveFile>();
            string pageToken = "";

            // Make sure we get all the pages of results
            do
            {
                args["pageToken"] = pageToken;
                string response = SendRequest(HttpMethod.GET, "https://www.googleapis.com/drive/v3/files", args, GoogleAuth.GetAuthHeaders());
                pageToken = "";

                if (!string.IsNullOrEmpty(response))
                {
                    GoogleDriveFileList fileList = JsonConvert.DeserializeObject <GoogleDriveFileList>(response);

                    if (fileList != null)
                    {
                        folders.AddRange(fileList.files);
                        pageToken = fileList.nextPageToken;
                    }
                }
            }while (!string.IsNullOrEmpty(pageToken));

            return(folders);
        }
Example #2
0
        public List <GoogleDriveFile> GetFolders(bool trashed = false, bool writer = true)
        {
            if (!CheckAuthorization())
            {
                return(null);
            }

            string query = "mimeType = 'application/vnd.google-apps.folder'";

            if (!trashed)
            {
                query += " and trashed = false";
            }

            if (writer)
            {
                query += " and 'me' in writers";
            }

            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("q", query);

            string response = SendRequest(HttpMethod.GET, "https://www.googleapis.com/drive/v2/files", args, GetAuthHeaders());

            if (!string.IsNullOrEmpty(response))
            {
                GoogleDriveFileList fileList = JsonConvert.DeserializeObject <GoogleDriveFileList>(response);

                if (fileList != null)
                {
                    return(fileList.items);
                }
            }

            return(null);
        }