問題描述
我正在創建一個可以將文件插入 Google Drive 并列出它的應用程序.我正在使用 Google Drive SDK v2 API.但我的問題是它沒有列出不是通過我的應用程序上傳的文件.如果我直接從 Google 驅動器上傳,它不會在我的應用程序中列出.
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.
列出文件的方法如下:
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 ...
推薦答案
我認為你使用了錯誤的 oauth 范圍,可能是 https://www.googleapis.com/auth/drive.file
當您應該使用 https://www.googleapis.com/auth/drive
來完全控制您的應用時,這會限制您的應用訪問您的應用創建或打開的文件.
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 use https://www.googleapis.com/auth/drive
which gives full control to your app.
這篇關于Google Drive SDK API沒有列出java中Google Drive上傳的文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!