def _get_token(self):
"""Get an API token.
Raises:
AuthenticationError: if getting token fails.
"""
client = BackendApplicationClient(client_id=CLIENT_ID)
oauth = OAuth2Session(client=client)
# Retry auth if error (to get around intermittent failures)
latest_exception = None
for i in range(3):
try:
token = oauth.fetch_token(
token_url=AUTH_URL, client_id=CLIENT_ID, client_secret=CLIENT_SECRET)
self.__token = token["access_token"]
self.__session = oauth
self._me = None
return
except (AccessDeniedError, InvalidClientError, MissingTokenError) as e:
latest_exception = e
continue
raise AuthenticationError("Failed to get authentication token: {0}".format(latest_exception))
评论列表
文章目录