云端硬盘文件未在云端硬盘API请求中列出

云端硬盘文件未在云端硬盘API请求中列出

本文介绍了云端硬盘文件未在云端硬盘API请求中列出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用桌面应用获取Google云端硬盘中的文件列表。代码如下:

  def main(argv):

storage = Storage('drive .dat')
credentials = storage.get()
$ b如果凭证是None或credentials.invalid:
credentials = run(流,存储)

#创建一个httplib2.Http对象来处理我们的HTTP请求,并用我们良好的凭证授权
#。
http = httplib2.Http()
http = credentials.authorize(http)

service = build(drive,v2,http = http)
retrieve_all_files(service)

然后在retrieve_all_files中,我打印这些文件:

  param = {} 
如果page_token:
param ['pageToken'] = page_token
files = service.files( ).list(** param).execute()
打印文件

但是当我向我的帐户进行身份验证,打印的文件列表中没有项目。有没有人有类似的问题或知道这个解决方案? 解决方案

如果我错了,请纠正我,但我相信您正在使用 https://www.googleapis.com/auth/drive.file 作用域,该作用域仅返回应用创建的文件或已经明确打开的文件使用或。



要检索所有文件,您需要使用更广的范围: https://www.googleapis.com/auth/drive



要了解有关不同范围的更多信息,请查看。


I am trying to get a list of the files in my Google Drive using a desktop app. The code is as follows:

def main(argv):

    storage = Storage('drive.dat')
    credentials = storage.get()

    if credentials is None or credentials.invalid:
        credentials = run(FLOW, storage)

    # Create an httplib2.Http object to handle our HTTP requests and authorize it
    # with our good Credentials.
    http = httplib2.Http()
    http = credentials.authorize(http)

    service = build("drive", "v2", http=http)
    retrieve_all_files(service)

Then in retrieve_all_files, I print the files:

param = {}
if page_token:
    param['pageToken'] = page_token
    files = service.files().list(**param).execute()
    print files

But after I authenticate to my account, the printed file list has no items. Does anyone have a similar problem or know of a solution to this?

解决方案

Please correct me if I'm wrong but I believe you are using the https://www.googleapis.com/auth/drive.file scope, which only returns files that your app has created or have been explicitly opened with your app using the Google Drive UI or the Picker API.

To retrieve all files, you will need to use the broader scope: https://www.googleapis.com/auth/drive.

To learn more about the different scopes, have a look at the documentation.

这篇关于云端硬盘文件未在云端硬盘API请求中列出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 07:35