Google Drive V3 Api获取文件名,C#

Fil*_*ajo 5 .net c# google-drive-api google-api-dotnet-client

如何使用驱动器api从get请求中获取单个文件名?

我已经提出了请求但是没有关于该文件的元数据,我只能下载它.

var fileId = "0BwwA4oUTeiV1UVNwOHItT0xfa2M";
var request = driveService.Files.Get(fileId);
Run Code Online (Sandbox Code Playgroud)

显然,这会根据此文档在响应中返回files.get

我只想下载一个文件并显示其名称,而不仅仅是其ID

DaI*_*mTo 0

尝试这个

    /// 
    /// Download a file
    /// Documentation: https://developers.google.com/drive/v2/reference/files/get
    /// 
    /// a Valid authenticated DriveService
    /// File resource of the file to download
    /// location of where to save the file including the file name to save it as.
    /// 
    public static Boolean downloadFile(DriveService _service, File _fileResource, string _saveTo)
    {

        if (!String.IsNullOrEmpty(_fileResource.DownloadUrl))
        {
            try
            {
                var x = _service.HttpClient.GetByteArrayAsync(_fileResource.DownloadUrl );
                byte[] arrBytes = x.Result;
                System.IO.File.WriteAllBytes(_saveTo, arrBytes);
                return true;                  
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occurred: " + e.Message);
                return false;
            }
        }
        else
        {
            // The file doesn't have any content stored on Drive.
            return false;
        }
    }
Run Code Online (Sandbox Code Playgroud)

代码来自我的Google Drive api C# 下载教程。我已经很久没有更新了,所以如果有任何问题请告诉我,我会修复它们。