我正在使用google-api-python-client和imapclient库来尝试获取对 Gmail 的 IMAP 访问权限。
通过身份验证流程时,我收到“无效范围”错误。我已经尝试过两者https://mail.google.com
和https://mail.google.com/mail/feed/atom
作为范围。
这是我正在尝试做的事情:
from oauth2client.appengine import OAuth2Decorator
SCOPE = "https://mail.google.com"
# SCOPE = "https://mail.google.com/mail/feed/atom"
oauth2decorator_gmail = OAuth2Decorator(client_id="CLIENT_ID",
client_secret="CLIENT_SECRET",
scope=SCOPE,
callback_path='/mycallbackurl')
class AuthenticateSyncServices(webapp2.RequestHandler):
@oauth2decorator_gmail.oauth_required
def get(self):
self.response.write("Authenticated")
这是堆栈跟踪:
INFO 2013-06-06 08:56:36,686 client.py:1304] Failed to retrieve access token: {
"error" : "invalid_scope"
}
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.1/webapp2.py", line 1536, in __call__
rv = self.handle_exception(request, response, e)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.1/webapp2.py", line 1530, in __call__
rv = self.router.dispatch(request, response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.1/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.1/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.1/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.1/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/util.py", line 68, in check_login
handler_method(self, *args)
File "/Users/John/Projects/my-app/backend/oauth2client/appengine.py", line 787, in get
credentials = decorator.flow.step2_exchange(self.request.params)
File "/Users/John/Projects/my-app/backend/oauth2client/util.py", line 128, in positional_wrapper
return wrapped(*args, **kwargs)
File "/Users/John/Projects/my-app/backend/oauth2client/client.py", line 1310, in step2_exchange
raise FlowExchangeError(error_msg)
FlowExchangeError: invalid_scope