2014-09-29 45 views
1

基地腳本:有問題通過的Oauth針-auth的會議越來越火力數據巢

from sanction import Client 
# client_id & client_secret are omitted but are valid 

client_pin = input('Enter PIN:') 

access_token_url = 'https://api.home.nest.com/oauth2/access_token' 

c = Client(
    token_endpoint=access_token_url, 
    client_id=client_id, 
    client_secret=client_secret) 

c.request_token(code = client_pin) 

[See edits for history]

運行c.request('/devices')返回:

Traceback (most recent call last): 
    File "C:\py\nest_testing_sanction.py", line 36, in <module> 
    c.request("/devices") 
    File "C:\Python34\lib\site-packages\sanction-0.4.1-py3.4.egg\sanction\__init__.py", line 169, in request 
    File "C:\Python34\lib\site-packages\sanction-0.4.1-py3.4.egg\sanction\__init__.py", line 211, in transport_query 
    File "C:\Python34\lib\urllib\request.py", line 258, in __init__ 
    self.full_url = url 
    File "C:\Python34\lib\urllib\request.py", line 284, in full_url 
    self._parse() 
    File "C:\Python34\lib\urllib\request.py", line 313, in _parse 
    raise ValueError("unknown url type: %r" % self.full_url) 
ValueError: unknown url type: 'None/devices?access_token=c.[some long session token]' 

鑑於輸出好像我需要要加入通用網址,所以我試過c.request('wss://developer-api.nest.com')

Traceback (most recent call last): 
    File "C:\py\nest_testing_sanction.py", line 36, in <module> 
    data = c.request(query_url) 
    File "C:\Python34\lib\site-packages\sanction-0.4.1-py3.4.egg\sanction\__init__.py", line 171, in request 
    File "C:\Python34\lib\urllib\request.py", line 153, in urlopen 
    return opener.open(url, data, timeout) 
    File "C:\Python34\lib\urllib\request.py", line 455, in open 
    response = self._open(req, data) 
    File "C:\Python34\lib\urllib\request.py", line 478, in _open 
    'unknown_open', req) 
    File "C:\Python34\lib\urllib\request.py", line 433, in _call_chain 
    result = func(*args) 
    File "C:\Python34\lib\urllib\request.py", line 1257, in unknown_open 
    raise URLError('unknown url type: %s' % type) 
urllib.error.URLError: <urlopen error unknown url type: nonewss> 

我也試過https按:

enter image description here - 同樣的結果

相比之下,這個工程(一firebase.io虛擬設備):

firebase = firebase.FirebaseApplication('https://nesttest.firebaseio.com', None) 
thermostat_result  = firebase.get('/devices', 'thermostats') 

回答

1

這是更多的評論,但系統不讓我評論。

對於你的問題,關於在哪裏把web引腳簡單地添加code = pin到request_token調用。

c.request_token(code = nest_client_pin) 

這仍然不能完全解決問題,因爲我只能使用一次PIN。在我使用過一次之後,隨後的每次呼叫都會按照您描述的方式再次失敗。仍在研究。

+0

謝謝,清除錯誤,基本上只是把我扔回到shell提示符。正如你所說的那樣,保持/重複使用會話是下一步。由於文檔幾乎不存在,因此我在這裏完全失敗。 – Enigma 2014-10-15 15:28:04

+0

同意。不容易得到這個工作。我會在業餘時間繼續努力...... – fxstein 2014-10-15 15:30:48

+0

所以我做了'c.request('/ devices')'之後出現錯誤,但它也輸出了看起來像是實際的會話令牌。不知道如何重用它,但也許這會幫助你..幫助我。 :) – Enigma 2014-10-15 15:48:18

2

在Python我想使用像sanction這樣的東西來保持簡單。你應該能夠得到它使用類似的代碼與鳥巢API的工作:(未經測試,使用令牌流量,而不是銷流量)

from sanction.client import Client 

# instantiating a client to get the auth URI 
c = Client(auth_endpoint="https://home.nest.com/login/oauth2", 
    client_id=config["nest.client_id"]) 

# instantiating a client to process OAuth2 response 
c = Client(token_endpoint="https://api.home.nest.com/oauth2/access_token", 
    client_id=config["nest.client_id"], 
    client_secret=config["nest.client_secret"]) 

庫是有據可查的,所以你應該能夠弄清楚從這裏如果有東西丟失。

+0

是否有關於銷流量的任何文檔(我沒有看到任何)?我沒有重定向URI。 – Enigma 2014-10-02 18:52:10

+0

要執行引腳流程,只需在您的客戶端中省略重定向URI,Nest將在身份驗證流程結束時向用戶顯示PIN。您可以像使用重定向中的access_token一樣使用PIN。 – 2014-10-07 22:43:38

+0

我是否甚至需要使用client_id/client_secret,如果我將這些內容嵌入到URL中:[https://api.home.nest.com/oauth2/access_token?code=AUTHORIZATION_CODE&client_id=CLIENT_ID&client_secret=CLIENT_SECRET&grant_type=authorization_code](https: //api.home.nest.com/oauth2/access_token?code=AUTHORIZATION_CODE&client_id=CLIENT_ID&client_secret=CLIENT_SECRET&grant_type=authorization_code)還是我假定Client()爲我做了這件事,我應該在'/ access_token'之後放棄所有事情? – Enigma 2014-10-08 16:04:33