无法使用python-firebase从nest中获取数据

时间:2016-05-05 09:01:45

标签: python firebase nest-api

我尝试使用python-firebase模块从nest获取数据但我无法获取。我遵循帖子What is the link between <YOUR-FIREBASE>.firebaseio.com and home.nest.com中给出的答案我有有效的嵌套令牌。

1 个答案:

答案 0 :(得分:1)

我不确定您要做什么,但您可能会考虑使用REST API而不是python-firebase。下面是使用请求库和ujson读取设备数据的代码示例。

import requests
import ujson

s = requests.session()

auth_url = "https://api.home.nest.com/oauth2/access_token"

auth_body = {
    "code": "AUTHORIZATION_CODE",
    "client_id": "CLIENT_ID",
    "client_secret": "CLIENT_SECRET",
    "grant_type": "authorization_code"
    }

auth_r = s.post(url=auth_url, data=auth_body)
auth_content = ujson.loads(auth_r.content)

auth_content['access_token']

devices_url = "https://developer-api.nest.com/devices?auth=" + auth_content['access_token']

devices_r = s.get(devices_url)

devices_r.json()