2016-10-20 18 views
-3

javaのGoogleドライブAPIを使用しています。コード内に子供のフォルダIDがありますが、子供のフォルダ名が必要です。私は子供のフォルダ名を取得するためにすべての方法を適用するが、私は0B3-sXIe4DGz1c3RhcnRlcl9のようなフォルダイドを得、このコードからGoogleドライブで子供のフォルダ名を取得する方法Javaを使用するドライブ

Drive.Children.List FolderID = service.children().list(child.getId()); 

を取得できませんでした。このコードで

Drive.Children.List Foldername = service.children().list(child.getId().getClass().getName()); 

それは返す{フォルダID = java.lang.Stringで}

は、どのように私は、フォルダの名前を得ることができますか?

+2

のドキュメントからリッピング ''クラス名以外の戻り? – f1sh

答えて

0

Googleドライブのフォルダにはファイルがあります。フォルダのタイトルを含むFileResourceを返すには、フォルダIDはFiles.getです。

コードを使用すると、 ``はgetClass()。のgetName()何を期待しFiles.get

import com.google.api.client.http.GenericUrl; 
import com.google.api.client.http.HttpResponse; 
import com.google.api.services.drive.Drive; 
import com.google.api.services.drive.model.File; 

import java.io.IOException; 
import java.io.InputStream; 

// ... 

public class MyClass { 

    // ... 

    /** 
    * Print a file's metadata. 
    * 
    * @param service Drive API service instance. 
    * @param fileId ID of the file to print metadata for. 
    */ 
    private static void printFile(Drive service, String fileId) { 

    try { 
     File file = service.files().get(fileId).execute(); 

     System.out.println("Title: " + file.getTitle()); 
     System.out.println("Description: " + file.getDescription()); 
     System.out.println("MIME type: " + file.getMimeType()); 
    } catch (IOException e) { 
     System.out.println("An error occured: " + e); 
    } 
    } 

    /** 
    * Download a file's content. 
    * 
    * @param service Drive API service instance. 
    * @param file Drive File instance. 
    * @return InputStream containing the file's content if successful, 
    *   {@code null} otherwise. 
    */ 
    private static InputStream downloadFile(Drive service, File file) { 
    if (file.getDownloadUrl() != null && file.getDownloadUrl().length() > 0) { 
     try { 
     HttpResponse resp = 
      service.getRequestFactory().buildGetRequest(new GenericUrl(file.getDownloadUrl())) 
       .execute(); 
     return resp.getContent(); 
     } catch (IOException e) { 
     // An error occurred. 
     e.printStackTrace(); 
     return null; 
     } 
    } else { 
     // The file doesn't have any content stored on Drive. 
     return null; 
    } 
    } 

    // ... 
} 
+0

私はすでにこれを使用していましたが、子供のフォルダ名が必要です – shikhasanadhya93

+0

タイトルは子フォルダの名前です。 printFile(service、 "0B3-sXIe4DGz1c3RhcnRlcl9") – DaImTo

+0

このメソッドが見つかりません。この方法を説明してください – shikhasanadhya93

関連する問題