2012-05-23 17 views

cevap

10

Bir klasör özel bir MIME türü olan bir dosya olarak ele alınabilir: "application/vnd.google-apps.folder". Daha fazla ayrıntı için

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(); 

docs kontrol:

aşağıdaki C# kodu neye ihtiyacınız olmalı Google Drive API olarak https://developers.google.com/drive/folder

+0

Klasör oluşturamıyorum ve hiçbir hata almadım. Ayrıca .Fetch() yöntemi benim için gelmiyor mu? Sürücüler nasıl başlatılır? Bunu şu şekilde kullanıyorum DriveService ds = new DriveService(); ds.Key = PicasaAuthToken; teşekkürler. – Sujit

+0

Kimlik doğrulamasını nasıl yapacağınızı öğrenmek için lütfen dokümanlar kontrol edin (https://developers.google.com/drive/apps_overview), Picasa auth jetonunun Drive ile ilgili bir yardımı yoktur. –

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

bir klasör Mime bir dosyaya başka bir şey değildir Tür: API v2 olarak application/vnd.google-apps.folder

, şunları kullanabilirsiniz:

// 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; 
} 

Kök dizinde klasör oluşturmak için, üst kimlik olarak "root" iletebilirsiniz.

İlgili konular