C# 没有通过C下载到Google Drive#

C# 没有通过C下载到Google Drive#,c#,google-drive-api,C#,Google Drive Api,在程序中,我需要下载到Google Drive。我在网上找到了一个例子。我按照这个例子做了所有的事情,但是出现了这样一个问题,代码运行正常,没有产生错误,但是在谷歌硬盘上没有出现任何文件 public static Google.Apis.Drive.v2.Data.File uploadFile(Google.Apis.Drive.v2.DriveService _service, string _uploadFile, string _parent) {

在程序中,我需要下载到Google Drive。我在网上找到了一个例子。我按照这个例子做了所有的事情,但是出现了这样一个问题,代码运行正常,没有产生错误,但是在谷歌硬盘上没有出现任何文件

public static Google.Apis.Drive.v2.Data.File uploadFile(Google.Apis.Drive.v2.DriveService _service, string _uploadFile, string _parent)
        {

            if (System.IO.File.Exists(_uploadFile))
            {
                Google.Apis.Drive.v2.Data.File body = new Google.Apis.Drive.v2.Data.File();
                body.Title = System.IO.Path.GetFileName(_uploadFile);
                body.Description = "File uploaded by .NET";
                body.MimeType = GetMimeType(_uploadFile);
                body.Parents = new List<Google.Apis.Drive.v2.Data.ParentReference>() { new Google.Apis.Drive.v2.Data.ParentReference() { Id = _parent } };

                // File's content.
                byte[] byteArray = System.IO.File.ReadAllBytes(_uploadFile);
                System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);
                try
                {
                    Google.Apis.Drive.v2.FilesResource.InsertMediaUpload request = _service.Files.Insert(body, stream, GetMimeType(_uploadFile));
                    request.Upload();
                    return request.ResponseBody;
                }
                catch (Exception e)
                {
                    MessageBox.Show("An error occurred: " + e.Message);
                    return null;
                }
            }
            else
            {
                MessageBox.Show("File does not exist: " + _uploadFile);
                return null;
            }
        }
public static Google.api.Drive.v2.Data.File上传文件(Google.api.Drive.v2.DriveService\u服务、字符串\u上传文件、字符串\u父项)
{
if(System.IO.File.Exists(_uploadFile))
{
Google.api.Drive.v2.Data.File body=新的Google.api.Drive.v2.Data.File();
body.Title=System.IO.Path.GetFileName(_uploadFile);
body.Description=“文件由.NET上传”;
body.MimeType=GetMimeType(_uploadFile);
body.Parents=new List(){new Google.api.Drive.v2.Data.ParentReference(){Id=\u parent}};
//文件的内容。
byte[]byteArray=System.IO.File.ReadAllBytes(\u uploadFile);
System.IO.MemoryStream stream=新的System.IO.MemoryStream(byteArray);
尝试
{
Google.api.Drive.v2.filesrource.InsertMediaUpload请求=_service.Files.Insert(body、stream、GetMimeType(_uploadFile));
request.Upload();
返回request.ResponseBody;
}
捕获(例外e)
{
MessageBox.Show(“发生错误:+e.Message”);
返回null;
}
}
其他的
{
Show(“文件不存在:”+\u uploadFile);
返回null;
}
}
发现部分代码
returnrequest.ResponseBody

返回Null,但我无法理解为什么会出现这种情况。

因为您使用的是v2驱动器API版本,我建议您检查哪些可以应用于C#/.NET。有一个关于如何实现它的代码示例。而且,它被称为“上传”而不是“下载到Google Drive”。因为您使用的是v2 Drive API版本,我建议您检查哪些可以应用到C#/.NET。有一个关于如何实现它的代码示例。它被称为“上传”,而不是“下载到谷歌硬盘”。