更新电子表格标题时出现Google Drive API 403错误

时间:2016-08-22 13:58:31

标签: python google-app-engine google-drive-api

我们在Google App Engine应用程序中使用Google Drive API。 本周末我们注意到它在更新电子表格标题方面存在问题。我们收到以下错误:

HttpError: <HttpError 403 when requesting https://www.googleapis.com/drive/v2/files/1_X51WMK0U12rfPKc2x60E_EuyqtQ8koW-NSRZq7Eqdw?quotaUser=5660071165952000&fields=title&alt=json returned "The authenticated user has not granted the app 593604285024 write access to the file 1_X51WMK0U12rfPKc2x60E_EuyqtQ8koW-NSRZq7Eqdw">

对Google Drive API的其他调用成功。我们只是遇到了这个问题。此功能也可以长时间正常工作。谷歌方面的某些更新是否有可能破坏了这一点?

重现问题的最小代码是:

class TestDriveUpdate(webapp2.RequestHandler):
    def get(self):
        credentials = StorageByKeyName(Credentials,
                                       '103005000283606027776',
                                       'credentials').get()
        spreadsheet_key = '1_X51WMK0U12rfPKc2x60E_EuyqtQ8koW-NSRZq7Eqdw'
        quota_user = '5660071165952000'
        body = {"title": 'Test'}
        fields = "title"

        http = httplib2.Http(timeout=60)
        credentials.authorize(http)
        gdrive = apiclient.discovery.build('drive', 'v2', http=http)
        response = gdrive.files().update(
                fileId=spreadsheet_key,
                body=body,
                fields=fields,
                quotaUser=quota_user
            ).execute()

        self.response.write("OK")

1 个答案:

答案 0 :(得分:1)

基于此documentation,如果请求的应用不在文件的ACL上,并且用户从未使用此云端硬盘应用明确打开该文件,则会发生错误。找到此SO question,其中指出范围字符串必须与您的代码和管理控制台之间完全匹配,包括尾部斜杠等。还要确保域中允许使用云端硬盘应用(“允许用户安装Google云端硬盘应用” “)。

相关问题