oauth-2.0 - Gmail API google.auth.exceptions.RefreshError 范围无效

标签 oauth-2.0 google-oauth gmail-api

我正在编写一个使用 gmail api 从邮箱下载报告的命令行工具。我正在使用 quickstart.py(转换为 python3)进行身份验证。但是,当 token 过期一段时间后无法刷新时,这会起作用。我得到:

File "/home/ayoub/.local/lib/python3.6/site-packages/google/oauth2/_client.py", line 248, in refresh_grant response_data = _token_endpoint_request(request, token_uri, body) File "/home/ayoub/.local/lib/python3.6/site-packages/google/oauth2/_client.py", line 124, in _token_endpoint_request _handle_error_response(response_body) File "/home/ayoub/.local/lib/python3.6/site-packages/google/oauth2/_client.py", line 60, in _handle_error_response raise exceptions.RefreshError(error_details, response_body) google.auth.exceptions.RefreshError: ('invalid_scope: Some requested scopes were invalid. {invalid=[a, c, e, g, h, i, l, m, ., /, o, p, s, t, :]}', '{\n "error": "invalid_scope",\n "error_description": "Some requested scopes were invalid. {invalid\u003d[a, c, e, g, h, i, l, m, ., /, o, p, s, t, :]}",\n "error_uri": "http://code.google.com/apis/accounts/docs/OAuth2.html"\n}')

我已确保我没有更改我的范围并创建了一个新的 credentials.json 文件。我还尝试升级所有使用的库。有没有人遇到过这个或知道解决方案?谢谢!

最佳答案

您收到的错误是由于范围声明不当造成的。声明范围的适当方式是这样的:

var SCOPES = ['SCOPE 1', 'SCOPE 2',...]

关于oauth-2.0 - Gmail API google.auth.exceptions.RefreshError 范围无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60329078/

相关文章:

oauth-2.0 - 在没有OAuth2的情况下访问Google云端硬盘

gmail - 有没有办法在 GMail API 中访问航类信息?

php - 如何在 PHP 中获取 OAuth 2.0 token ?

google-apps-script - Bing Ads API v2 oAuth2

oauth - 有没有办法从外部应用程序修改在 Google 日历中创建的事件?

node.js - 如何将 Google OAuth2 ID token 与 node.js/passport.js 一起使用来验证用户是否有效并经过身份验证?

javascript - 电子邮件被回复给收件人而不是发件人或回复地址

google-api - Google Gmail API - 委派设置

azure - 如何在 Azure AD 中设置应用程序的资源名称

通过 SSL 的 ASP.NET oAuth 访问 token