Google驱动器返回空文件

时间:2015-06-21 14:12:33

标签: android google-drive-api

我正在创建一个从谷歌驱动器访问文件的应用程序。我正在使用this链接访问google驱动器中的文件。方法Files.List request = service.files().list();一直为我返回{}。我在这里发布我的所有代码。

private Drive getDriveService() {
    try {
        GoogleAccountCredential credential = GoogleAccountCredential
                .usingOAuth2(MainActivity.this, DriveScopes.DRIVE_FILE);
        credential.setSelectedAccountName("Sachinkamboj1989@gmail.com");

        drive = new Drive.Builder(AndroidHttp.newCompatibleTransport(),
                new GsonFactory(), credential).build();
        drive.children();
        drive.files();
        new Thread(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                try {
                    retrieveAllFiles1(drive);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }).start();

    } catch (Exception e) {

        e.printStackTrace();
    }
    return drive;

}

private static List<File> retrieveAllFiles1(Drive service)
        throws IOException {
    List<File> result = new ArrayList<File>();
    Files.List request = service.files().list();

    do {
        try {
            FileList files = request.execute();
            System.out.println(files);
            result.addAll(files.getItems());
            request.setPageToken(files.getNextPageToken());
        } catch (IOException e) {
            System.out.println("An error occurred: " + e);
            request.setPageToken(null);
        }
    } while (request.getPageToken() != null
            && request.getPageToken().length() > 0);
    // System.out.println(result);
    return result;
}

访问文件的方法是

0 个答案:

没有答案