2014-07-09 3 views
3

tl; dr : 빈 폴더를 Google 드라이브에 업로드 할 수 없습니다. Google API가 명확하지 않으며 도움이 필요합니다.폴더 만 Google 드라이브에 업로드하는 방법

Google 드라이브에 빈 폴더를 업로드 할 수있는 프로그램을 만들려고합니다. 폴더 작업을 위해 Google 드라이브 API를 살펴 봤는데 분명하지 않아서 사람들이 명확한 대답을 줄 수 있다면 감사하게 생각합니다!

파일 업로드를 위해 Google에서 소스 코드를 전환하려고했습니다. 즉, body.mimeType = "application/vnd.google-apps.folder"; 등등. 폴더를 byteArray로 변환 할 수 없기 때문에 UnauthorizedAccessException 오류가 발생합니다.

저는 C#에 대한 지식이별로 없으므로이 문제를 해결하는 방법을 모르겠습니다. 코드 스 니펫을 포함시켜 코드를 어디에 넣을 지 시각화 할 수 있다면 좋을 것입니다.

코드 :

Google.Apis.Drive.v2.Data.File folder = new Google.Apis.Drive.v2.Data.File(); 
     folder.Title = My Folder; 
     folder.Description = desc.; 
     folder.MimeType = applicationvnd.google-apps.folder; 
     //Tried^that, didn't work 

     FilesResource.InsertMediaUpload request = service.Files.Insert(folder).Fetch(); 
     Google.Apis.Drive.v2.Data.File file = service.Files.Insert(folder).Fetch(); 
     File file = service.Files.Insert(folder).Fetch(); 
     //Again, tried those but that didn't work either 

     File body = new File(); 
     body.Title = "Document"; 
     body.Description = "A test folder"; 
     body.MimeType = "application/vnd.google-apps.folder"; 

     byte[] byteArray = System.IO.File.ReadAllBytes("Folder"); 
     //I know this doesn't work but had to try anyways 
     System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray); 

     FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, "application/vnd.google-apps.folder"); 
     request.Upload(); 

     File file = request.ResponseBody; 
     Console.WriteLine(File id + file.Id); 

나는 그게 내가 무엇을 시도했다 대부분에 대한 생각, 각각 작동하지 않았다. 내가 시도한 다른 것들이 있었지만 그 이후로 코드를 지우고 다시 작동하지 않기 때문에 다시 찾지 못했습니다.

감사합니다.

+0

일부 코드보기 ... – Matt

+0

[Google 드라이브에서 폴더를 만드는 방법 C# net api를 사용하는 방법] (http://stackoverflow.com/questions/10715962/how-to-create-folder-in-google -drive-using-c-sharp-net-api) – mason

+0

@mason 나는 이미 그 링크에 대한 해답을 시도해 봤으며 거기에 주석이 달린 것처럼 .Fetch()도 나를 위해 작동하지 않는다. – Noob

답변

2

나는 (다른 질문에 대한 답변을 찾아) 그것을 해결 대신 파일 파일의

을 = service.Files.Insert (몸) .Fetch(); (많은 사람들은 이것이 작동하지 않는다고 말했습니다.) File file = service.Files.Insert (body)를 사용하십시오. 실행(); 찬성 투표 (또는이 포럼은 작동하지만) 여기에 답 : Create folder on Google Drive .NET

코드 : 그것이 및 포함되지 않은 어떤 코드를 볼 수 있습니다 내가 찾을 수 있기 때문에

File body = new File(); 
     body.Title = "document title"; 
     body.Description = "document description"; 
     body.MimeType = "application/vnd.google-apps.folder"; 

     // service is an authorized Drive API service instance 
     File file = service.Files.Insert(body).Execute(); 

     //File body = new File(); 
     //body.Title = "My document"; 
     //body.Description = "A test document"; 
     //body.MimeType = "text/plain"; 

     //byte[] byteArray = System.IO.File.ReadAllBytes("document.txt"); 
     //System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray); 

     //FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, "text/plain"); 
     //request.Upload(); 

     //File file = request.ResponseBody; 

은 내가 주석 모두에 넣어 그것을 위해 작동합니다. 그 전에 소스 코드의 모든 내용이 참조 용으로 Google의 빠른 시작 C#을 참조하십시오.

희망 사항은 동일한 문제가있는 다른 모든 사용자에게 도움이되기를 바랍니다.

관련 문제