我正在使用C#,Google .NET API。如何在Google雲端硬盤根目錄位置創建文件夾?任何代碼都會有幫助。謝謝如何使用.NET API在Google Drive中創建文件夾?
5
A
回答
10
可以將文件夾視爲具有特殊MIME類型的文件:「application/vnd.google-apps.folder」。
下面的C#代碼應該是你所需要的:
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).Fetch();
0
//First you will need a DriveService:
ClientSecrets cs = new ClientSecrets();
cs.ClientId = yourClientId;
cs.ClientSecret = yourClientSecret;
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
cs,
new[] { DriveService.Scope.Drive },
"user",
CancellationToken.None,
null
).Result;
DriveService service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "TheAppName"
});
//then you can upload the file:
File body = new File();
body.Title = "document title";
body.Description = "document description";
body.MimeType = "application/vnd.google-apps.folder";
File folder = service.Files.Insert(body).Execute();
0
在谷歌雲端硬盤API,一個文件夾是什麼,但使用MIME文件類型:application/vnd.google-apps.folder
在API第2版,您可以使用:
// DriveService _service: Valid, authenticated Drive service
// string_ title: Title of the folder
// string _description: Description of the folder
// _parent: ID of the parent directory to which the folder should be created
public static File createDirectory(DriveService _service, string _title, string _description, string _parent)
{
File NewDirectory = null;
File body = new File();
body.Title = _title;
body.Description = _description;
body.MimeType = "application/vnd.google-apps.folder";
body.Parents = new List<ParentReference>() { new ParentReference() { Id = _parent } };
try
{
FilesResource.InsertRequest request = _service.Files.Insert(body);
NewDirectory = request.Execute();
}
catch(Exception e)
{
MessageBox.Show(e.Message, "Error Occured");
}
return NewDirectory;
}
要在根目錄下創建文件夾,可以將"root"
作爲父ID。
相關問題
- 1. 在Google Drive .NET上創建文件夾
- 2. 如何使用Python中的Google Drive API創建新文件夾?
- 3. Google Drive API - 創建重複文件夾
- 4. Google Drive API上傳/創建文件(.NET)
- 5. 使用JavaScript API在Google Drive中創建文件夾
- 6. 如何使用javascript在Google Drive上創建文件夾
- 7. Google Drive API - 使用.NET列出文件夾內的文件
- 8. 使用Google Drive .NET API創建文件的空響應
- 9. 在Google Drive中創建文件夾內的文件夾android
- 10. 使用Google Drive API下載文件夾
- 11. 如何使用Google Drive REST AP和HTTPClient創建文件夾?
- 12. 使用Google Drive iOS API,我如何創建文件夾並共享它?
- 13. 如何通過Google腳本在Drive中的文件夾內創建文件夾?
- 14. 在Google Drive中使用rest api界面和python請求創建文件夾
- 15. 使用Google Drive API - 如何顯示根文件夾中的文件夾列表
- 16. 如何使用Google Drive API獲取文件夾的子女數?
- 17. 如何獲取Google Drive Android API中已創建文件夾的DriveId
- 18. 使用Google Drive Viewer顯示通過Google Drive API創建的文件
- 19. Google Drive API - 獲取文件夾列表
- 20. Google Drive API上傳到父文件夾
- 21. Google Drive API文件夾權限
- 22. 使用Google Drive SDK創建文件夾iOS
- 23. Google Drive API文件夾/兒童ID
- 24. 使用google-drive-api將文件插入到特定文件夾
- 25. 使用Google Drive API列出GDrive的文件和文件夾
- 26. 使用Google Drive API/SDK插入新的文件夾和文件
- 27. Google Drive API v3在特定文件夾中查找文件
- 28. 在Google Drive SDK中一次創建多個文件夾
- 29. 如何在Google Drive中獲取My Drive的子文件夾
- 30. 如何使用Drive API建立與Google雲端硬盤文件夾的連接
我無法創建文件夾,也沒有收到錯誤。而且.Fetch()方法不適合我? 如何實例化driveservice?我正在使用它像這樣 DriveService ds = new DriveService(); ds.Key = PicasaAuthToken; 謝謝。 – Sujit
請檢查文檔以瞭解如何執行身份驗證(https://developers.google.com/drive/apps_overview),Picasa身份驗證令牌對雲端硬盤無效。 –