{"action":"opened","issue":{"url":"https://api.github.com/repos/orcasgit/python-fitbit/issues/86","repository_url":"https://api.github.com/repos/orcasgit/python-fitbit","labels_url":"https://api.github.com/repos/orcasgit/python-fitbit/issues/86/labels{/name}","comments_url":"https://api.github.com/repos/orcasgit/python-fitbit/issues/86/comments","events_url":"https://api.github.com/repos/orcasgit/python-fitbit/issues/86/events","html_url":"https://github.com/orcasgit/python-fitbit/issues/86","id":144362134,"number":86,"title":"make_request inside FitbitOauth2Client does not handle refresh on expired token correctly","user":{"login":"xuefanzhang","id":2301245,"avatar_url":"https://avatars.githubusercontent.com/u/2301245?v=3","gravatar_id":"","url":"https://api.github.com/users/xuefanzhang","html_url":"https://github.com/xuefanzhang","followers_url":"https://api.github.com/users/xuefanzhang/followers","following_url":"https://api.github.com/users/xuefanzhang/following{/other_user}","gists_url":"https://api.github.com/users/xuefanzhang/gists{/gist_id}","starred_url":"https://api.github.com/users/xuefanzhang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xuefanzhang/subscriptions","organizations_url":"https://api.github.com/users/xuefanzhang/orgs","repos_url":"https://api.github.com/users/xuefanzhang/repos","events_url":"https://api.github.com/users/xuefanzhang/events{/privacy}","received_events_url":"https://api.github.com/users/xuefanzhang/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-03-29T19:22:41Z","updated_at":"2016-03-29T19:22:41Z","closed_at":null,"body":"Hi there,\r\n\r\nI think there is a problem with token refreshing. On expired_token, _fitbit.exceptions.HTTPUnauthorized: Access token expired _ is still being thrown instead of handled correctly. https://github.com/orcasgit/python-fitbit/blob/master/fitbit/api.py#L82.\r\n\r\nInside the if condition, it checks d['errors'][0]['errorType'] == 'oauth' and ... and calls self.refresh_token() when that condition is met, but the errorType is 'expired_token' not 'oauth'. This is the JSON body:\r\n\r\n{u'errors': [{u'errorType': u'expired_token',\r\n              u'message': u'Access token expired: [_omitting_token_string here_]. Visit https://dev.fitbit.com/docs/oauth2 for more information on the Fitbit Web API authorization process.'}],\r\n u'success': False}\r\n\r\nAs a result it's never retried and we get the access token expired exception later again.\r\n\r\nLet me know if my understanding of how this works/doesn't work is correct :)..."}}