Google云端硬盘SDK API未列出Google云端硬盘在java中上传的文件 [英] Google Drive SDK API does not lists the file uploaded by Google Drive in java
问题描述
我正在创建一个可以将文件插入Google云端硬盘并将其列出的应用程序。我正在使用Google Drive SDK v2 API。但我的问题是它没有列出没有通过我的应用程序上传的文件。如果我直接从Google驱动器上传它,它不会列在我的应用程序中。
以下是列出文件的方法:
private static List< File> retrieveAllFiles(Drive service)抛出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(发生错误:+ e);
request.setPageToken(null); $()$ null)
}
} while(request.getPageToken()!= null&&
request.getPageToken()。length()> 0);
返回结果;
}
我正在迭代这样的文件:
列表< File> files = retrieveAllFiles(service);
for(File f:files){
System.out.println(File Name:+ f.getOriginalFilename();
}
任何人都可以帮助我?请提前致谢...
解决方案我认为您使用的是错误的oauth范围,可能https://www.googleapis.com/auth/drive.file
,这会限制您的应用程序的访问权限文件创建或打开您的应用程序,当您应该使用https://www.googleapis.com/auth/drive
,它可以完全控制您的应用程序。I am creating an application which can insert files into Google Drive and lists it. I am using Google Drive SDK v2 API. But my problem is it is not listing files which is not uploaded through my application. If I upload directly from Google drive it is not listed in my application.
Here is the method to list the file:
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; }
and I am iterating files like this :
List<File> files = retrieveAllFiles(service); for(File f : files) { System.out.println("File Name : "+f.getOriginalFilename(); }
Can anyone help me please ? Thanks in advance ...
解决方案I think you are using the wrong oauth scope, probably
https://www.googleapis.com/auth/drive.file
which restrict your app's access to file created or opened by your app, when you should usehttps://www.googleapis.com/auth/drive
which gives full control to your app.这篇关于Google云端硬盘SDK API未列出Google云端硬盘在java中上传的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文