Google Drive SDK API没有列出java中Google Drive上传的文件

Google Drive SDK API does not lists the file uploaded by Google Drive in java(Google Drive SDK API没有列出java中Google Drive上传的文件)
本文介绍了Google Drive SDK API没有列出java中Google Drive上传的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在创建一个可以将文件插入 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上传的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Reliable implementation of PBKDF2-HMAC-SHA256 for JAVA(PBKDF2-HMAC-SHA256 for JAVA 的可靠实现)
Correct way to sign and verify signature using bouncycastle(使用 bouncycastle 签名和验证签名的正确方法)
Creating RSA Public Key From String(从字符串创建 RSA 公钥)
Why java.security.NoSuchProviderException No such provider: BC?(为什么 java.security.NoSuchProviderException 没有这样的提供者:BC?)
Generating X509 Certificate using Bouncy Castle Java(使用 Bouncy Castle Java 生成 X509 证书)
How can I get a PublicKey object from EC public key bytes?(如何从 EC 公钥字节中获取 PublicKey 对象?)