Skip to main content
 首页 » 编程设计

python之YOUR-FIREBASE>.firebaseio.com 和 home.nest.com 之间的链接是什么

2025年05月04日15虾米哥

我可以使用 python-firebase 与 firebaseio 对话但我没有找到任何关于如何使用 firebaseio 与 NEST 设备进行实际通信的教程。

firebaseio 上的所有示例都与 NEST 无关,同样,NEST 示例似乎也与 firebaseio 无关。

firebaseio 帐户是否应该以某种方式从 home.nest.com 导入数据?如何将两者联系起来?


为什么我要使用 firebaseio 进行身份验证,除非它有 NEST 的数据?

python-firebase :

Authentication

Authentication in Firebase is nothing but to simply creating a token that conforms to the JWT standarts and, putting it into the querystring with the name auth. The library creates that token for you so you never end up struggling with constructing a valid token on your own. If the data has been protected against write/read operations with some security rules, the backend sends an appropriate error message back to the client with the status code 403 Forbidden.

from firebase import firebase 
firebase = firebase.FirebaseApplication('https://your_storage.firebaseio.com', authentication=None) 
result = firebase.get('/users', None, {'print': 'pretty'}) 
print result 
{'error': 'Permission denied.'} 
 
authentication = firebase.Authentication('THIS_IS_MY_SECRET', 'ozgurvt@gmail.com', extra={'id': 123}) 
firebase.authentication = authentication 
print authentication.extra 
{'admin': False, 'debug': False, 'email': 'ozgurvt@gmail.com', 'id': 123, 'provider': 'password'} 
 
user = authentication.get_user() 
print user.firebase_auth_token 
"eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.eyJhZG1pbiI6IGZhbHNlLCAiZGVidWciOiBmYWxzZSwgIml 
hdCI6IDEzNjE5NTAxNzQsICJkIjogeyJkZWJ1ZyI6IGZhbHNlLCAiYWRtaW4iOiBmYWxzZSwgInByb3ZpZGVyIjog 
InBhc3N3b3JkIiwgImlkIjogNSwgImVtYWlsIjogIm96Z3VydnRAZ21haWwuY29tIn0sICJ2IjogMH0.lq4IRVfvE 
GQklslOlS4uIBLSSJj88YNrloWXvisRgfQ" 
 
result = firebase.get('/users', None, {'print': 'pretty'}) 
print result 
{'1': 'John Doe', '2': 'Jane Doe'} 

请您参考如下方法:

Nest 运营自己的服务器,这些服务器与 Firebase 托管服务协议(protocol)兼容。也就是说,存在一些细微差别。虽然您仍然可以使用 Firebase 客户端库(和 REST 包装器,如 python-firebase),但您需要遵循特定说明(Nest Intro here)。

主要变化必须处理如何创建新的 Firebase 实例:而不是使用 https://<your-firebase>.firebaseio.com , 你使用 wss://developer-api.nest.com .然后,您使用 Nest 身份验证 token 进行身份验证。嵌套的 JS 看起来像:

var dataRef = new Firebase('wss://developer-api.nest.com'); 
dataRef.auth(nestToken); 

Python 看起来应该类似:

from firebase import firebase 
authentication = firebase.Authentication('YOUR_NEST_TOKEN', 'YOUR_EMAIL', extra={}) 
firebase = firebase.FirebaseApplication('wss://developer-api.nest.com', authentication) 

通常对于 Nest,您只需要 token ,而不是电子邮件或额外的,这意味着您可能必须使用其他 python-firebase library ,或修改源以允许提供程序而不是包装简单登录。看起来原始库从不使用电子邮件字段(参见 this 评论)。必须进行的另一个更改是 change the asserts所有 Firebase 网址都以 https 开头而是让他们以 https 开头或 wss .

此外,您可以使用 Vulcan,而不是使用常规的 Firebase 工具(例如 <your-firebase>.firebaseio.com 的 Firebase 仪表板,或我们的 Chrome 扩展程序 Nest Chrome Extension)管理您的 Nest 设备。

希望这对您有所帮助!