未与我共享的文件夹列表,Google Drive API [英] List of folder not shared with me, Google Drive API

查看:93
本文介绍了未与我共享的文件夹列表,Google Drive API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我想列出驱动器中存在的所有文件夹,但是我不知道该怎么做.我只想在我的云端硬盘"中列出文件夹,而不要在与我共享"中列出文件夹.

In my application, I want to list all folder that exist in my drive, but I don't know how to do it. I want to list folder just in "My Drive" not in "Shared with me".

这是我的代码:

 Dim fold = Service.Files.List()
       fold.Q = "mimeType = 'application/vnd.google-apps.folder'  and trashed = false and 'me' in owners "

但是我有一个例外:Invalid Query [400]

推荐答案

您可以引用此此外,includeTeamDriveItems已被设置为默认值 false .在这里,您可以设置是否要在结果中包括团队合作精神.

Also, the includeTeamDriveItems was already set to false as a default value. From here, you will be able to set if you want to include team drives in the result.

尝试快速入门中的代码.

Try the code from the quickstart.

using Google.Apis.Auth.OAuth2;
using Google.Apis.Drive.v3;
using Google.Apis.Drive.v3.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace DriveQuickstart
{
    class Program
    {
        // If modifying these scopes, delete your previously saved credentials
        // at ~/.credentials/drive-dotnet-quickstart.json
        static string[] Scopes = {  DriveService.Scope.DriveReadonly };
        static string ApplicationName = "Drive API .NET Quickstart";

        static void Main(string[] args)
        {
            UserCredential credential;

            using (var stream =
                new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = System.Environment.GetFolderPath(
                    System.Environment.SpecialFolder.Personal);
                credPath = Path.Combine(credPath, ".credentials/drive-dotnet-quickstart.json");

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            // Create Drive API service.
            var service = new DriveService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName = ApplicationName,
                });

            // Define parameters of request.
            FilesResource.ListRequest listRequest = service.Files.List();
            listRequest.PageSize = 10;
            listRequest.Fields = "nextPageToken, files(id, name)";

            // List files.
            IList<Google.Apis.Drive.v3.Data.File> files = listRequest.Execute()
                .Files;
            Console.WriteLine("Files:");
            if (files != null && files.Count > 0)
            {
                foreach (var file in files)
                {
                    Console.WriteLine("{0} ({1})", file.Name, file.Id);
                }
            }
            else
            {
                Console.WriteLine("No files found.");
            }
            Console.Read();

        }
    }
}

关于您的错误,我认为您正在尝试使用特定于两个不同版本的搜索参数, Drive v3 API Drive v2 API

Regarding your error, I think you are trying to use search parameters specific for two different versions, Drive v3 API and Drive v2 API

您可以参考此 SO帖子以获取更多信息信息.

You can refer to this SO post for further information.

这篇关于未与我共享的文件夹列表,Google Drive API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆