未授予Google云端硬盘API的读取访问权限 [英] Google Drive API read access not granted

查看:651
本文介绍了未授予Google云端硬盘API的读取访问权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Google Drive API从Google Drive下载随机文件.尽管在运行代码后我收到一条错误消息:用户尚未授予应用程序(app_code)对文件(文件名)的读取权限.如何授予对该文件的读取访问权限?我在互联网上和API控制台中都找不到任何内容.

I am trying to download a random file from a Google Drive using Google Drive API. Although after running the code I got an error message: The user has not granted the app (app_code) read access to the file (filename). How can I grant a read access to the file? I haven't found anything on the internet, and in the API Dashboard either.

 # Call the Drive v3 API
    results = service.files().list(
        pageSize=1000, fields="nextPageToken, files(id, name)").execute()
    items = results.get('files', [])
    rand_item = random.choice(items)
    print('{0} ({1})'.format(rand_item['name'], rand_item['id']))
    if not items:
        print('No files found.')
    else:
        request = service.files().get_media(fileId=rand_item['id'])
        fh = io.BytesIO()
        downloader = MediaIoBaseDownload(fh, request)
        done = False
        while done is False:
            status, done = downloader.next_chunk()
            print("Download %d%%." % int(status.progress() * 100))

完整代码: Pastebin

推荐答案

取决于范围.您只授予了metadata.readonly访问权限

Its due to the scope. You only gave metadata.readonly access

将其更改为 'https://www.googleapis.com/auth/drive.readonly'


Google云端硬盘API授权

这篇关于未授予Google云端硬盘API的读取访问权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆