Google Drive SDK API未列出Google Drive在java中上载的文件
我正在创建一个应用程序,可以插入文件到谷歌驱动器,并列出它。我使用的是Google Drive SDK v2 API。但我的问题是它没有列出没有通过我的应用程序上传的文件。如果我直接从谷歌硬盘上传,它不会列在我的应用程序中 以下是列出文件的方法:Google Drive SDK API未列出Google Drive在java中上载的文件,java,google-drive-api,Java,Google Drive Api,我正在创建一个应用程序,可以插入文件到谷歌驱动器,并列出它。我使用的是Google Drive SDK v2 API。但我的问题是它没有列出没有通过我的应用程序上传的文件。如果我直接从谷歌硬盘上传,它不会列在我的应用程序中 以下是列出文件的方法: private static List<File> retrieveAllFiles(Drive service) throws IOException { List<File> result = new Arr
private static List<File> retrieveAllFiles(Drive service) throws IOException {
List<File> result = new ArrayList<File>();
Files.List request = service.files().list();
do {
try {
FileList files = request.execute();
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);
return result;
}
私有静态列表检索所有文件(驱动器服务)引发IOException{
列表结果=新建ArrayList();
Files.List请求=service.Files().List();
做{
试一试{
FileList files=request.execute();
result.addAll(files.getItems());
request.setPageToken(files.getNextPageToken());
}捕获(IOE异常){
System.out.println(“发生错误:“+e”);
request.setPageToken(null);
}
}while(request.getPageToken()!=null&&
request.getPageToken().length()>0);
返回结果;
}
我正在迭代这样的文件:
List<File> files = retrieveAllFiles(service);
for(File f : files) {
System.out.println("File Name : "+f.getOriginalFilename();
}
List files=检索所有文件(服务);
用于(文件f:文件){
System.out.println(“文件名:”+f.getOriginalFilename();
}
有人能帮我吗?提前谢谢…我想你用错了oauth范围,可能是
https://www.googleapis.com/auth/drive.file
当您应该使用https://www.googleapis.com/auth/drive
可完全控制您的应用程序。我也有同样的问题。你能告诉我如何解决吗?我已经被它绊倒了好几天了将oauth范围更改为https://www.googleapis.com/auth/drive
我正在使用java android。我不知道在哪里更改该范围。这是我的代码,你能看一下@Dolphin吗,对不起,伙计,我对android一无所知,但更改范围可能会让你更满意我也要解决你的问题。谢谢你的帮助,我会找到答案:)@PrabhatSubedi:Google最近有没有改变什么……按照建议更改范围仍然只列出我的应用程序创建的文件@llamawithabowlcut当前不在Google Drive中工作。。。更好地查找SDK的文档和版本。