我正在开发一个 AppEngine 应用程序,它使用 Google Drive API 列出我的 Google Drive 中的文件。当我的一位用户尝试运行我的应用程序时,我收到 500 错误:
HttpError:https://www.googleapis.com/drive/v2/files?q=%27[ID sanitized]%27+in+parents&alt=json&maxResults=5 返回“无效凭据”>
该代码从特定的谷歌驱动器文件夹中提取文件。该文件夹和文件与用户共享,并且该应用程序被授权使用 Google Drive API。
在某些时候,我认为我应该从头开始,所以我撤销了该用户帐户的授权。似乎没有什么不同,现在增加侮辱伤害似乎我的应用程序不再要求该特定用户授权。
在这一点上有人有什么建议吗?我的代码使用 Python 的 Google API 客户端和装饰器(带有 oauth_required)来处理授权:
CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), 'client_secrets.json')
MISSING_CLIENT_SECRETS_MESSAGE = """
<h1>Warning: Please configure OAuth 2.0</h1>
<p>
To make this sample run you will need to populate the client_secrets.json file
found at:
</p>
<p>
<code>%s</code>.
</p>
<p>with information found on the <a
href="https://code.google.com/apis/console">APIs Console</a>.
</p>
""" % CLIENT_SECRETS
http = httplib2.Http(memcache)
service = build("plus", "v1", http=http)
files_service = build("drive", "v2", http=http)
decorator = oauth2decorator_from_clientsecrets(
CLIENT_SECRETS,
scope='https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/drive.readonly',
message=MISSING_CLIENT_SECRETS_MESSAGE)
[...]
class MainPage(webapp2.RequestHandler):
@decorator.oauth_required
def get(self):
[...]
try:
kb_param = {}
kb_param["maxResults"] = 5
kb_param["q"] = "'[sanitized]' in parents"
kb_files = files_service.files().list(**kb_param).execute(http=http)
template_values = {
'kb_files': kb_files["items"]
}
任何见解将不胜感激:)
谢谢!瑞克。