Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# GoogleAPI媒体上传返回空值_C#_Api - Fatal编程技术网

C# GoogleAPI媒体上传返回空值

C# GoogleAPI媒体上传返回空值,c#,api,C#,Api,我试图上传一个文件到谷歌驱动器,但每次它返回空。 C#新手我不知道C#的端口,但是java版本的结构有点不同。你能提供C#文档的链接吗。我不知道C#的端口,但是java版本的结构有点不同。你能提供C#文档的链接吗。 private static void Upload(string path, DriveService driveService) { var fileMetadata = new Google.Apis.Drive.v2.D

我试图上传一个文件到谷歌驱动器,但每次它返回空。
C#新手

我不知道C#的端口,但是java版本的结构有点不同。你能提供C#文档的链接吗。我不知道C#的端口,但是java版本的结构有点不同。你能提供C#文档的链接吗。
        private static void Upload(string path, DriveService driveService)
        {
            var fileMetadata = new Google.Apis.Drive.v2.Data.File()
            {
                Title = "photo.jpg",
            };
            FilesResource.InsertMediaUpload request;
            using (var stream = new System.IO.FileStream(path,System.IO.FileMode.Open))
            {
                request = driveService.Files.Insert(fileMetadata, stream, "image/jpeg");
                request.Fields = "id";
                request.Upload();
            }
            var file = request.ResponseBody;
            Console.WriteLine("File ID: " + file.Id);

        }