2016-06-28 48 views
0

我遇到了Jawbone API的問題。當我使用https://github.com/karthikbgl/python-jawbone-up.git單步執行oauth proess時,我可以成功接收授權碼,然後獲取令牌。收到相同的無效Jawbone Api令牌

def access_token(self, code, grant_type='authorization_code'): 
    ''' 
    Get the access code for a user with a auth code. 
    ''' 

    params = { 
     'code'   : code, 
     'client_id'  : self.client_id, 
     'client_secret' : self.client_secret, 
     'grant_type' : grant_type 
    } 

    context = { 
     'base_url': self.base_url, 
     'params' : urllib.urlencode(params) 
    } 

    headers = { 
     'Content-Type': 'application/x-www-form-urlencoded', 
     'Accept': 'application/json', 
     'X-Target-URI': 'https://jawbone.com', 
     'host': 'jawbone.com' 
    } 

    token_url = '{base_url}auth/oauth2/token/?{params}'.format(**context) 

    res = requests.get(token_url, headers=headers) 
    return res.json() 

但是我收到的令牌始終是相同的,而當我用它來調用API,我收到錯誤:

{"meta": {"code": 401, "error_detail": "You must be logged in to perform that action", "error_type": "authentication_error", "message": "Unauthorized"}, "data": {}} 

此外,如果我使用一個名爲access_jawbone與此模塊代碼:

params = urllib.urlencode({ 
          'email': username, 
          'pwd': password, 
          'service': 'nudge' 
          }) 

tokenresponse = urllib2.urlopen(url, params) 

我得到一個有效的令牌,可以訪問API。

有誰知道爲什麼提供OAuth令牌不工作

下面的問題似乎解決了同樣的問題,但我不明白的答案或如何解決我的問題。 Jawbone UP API oAuth and Access Tokens

回答

0

我有同樣的問題。我認爲這個答案是正在發生的事情: https://stackoverflow.com/a/32984287/1732987

要解決它,我必須通過瀏覽器來註銷所有Jawbone的東西在,從我的新的應用程序數據庫中刪除訪問令牌,並開始在過程中的標誌從一個乾淨的石板。