我无法获取Nest的访问令牌。
我在我的node.js应用程序上运行了nest-api,但是我无法访问令牌。
如果我从不同的客户端,设备甚至帐户连接都没关系。
我曾经拥有自动获取令牌的oAuth 2.0流程的PHP代码,但它运行正常,但它已停止工作。
如果我将“OAuth重定向网址”设置为自动获取令牌或者只是尝试在没有网址的情况下获取令牌并不重要,我总是会收到此错误:
发生错误。获取客户端信息时发生错误
这就是全部,没有日志条目或任何东西,只是那些非描述性的消息。
例如,如果我创建一个新帐户,然后我将客户端添加到此帐户,我会得到一个URL,我可以在其中检索想要从我的客户端控制其嵌套产品的用户帐户的访问令牌 - URL看起来像这样:
https://home.testc.nestlabs.com/login/oauth2?client_id=XXXXX&state=STATE
当您输入此URL时,它应该询问您的Nest凭据,然后生成访问令牌。 这工作正常,完成相同的步骤,但现在它甚至没有要求凭据,我得到的只是那条消息而没有别的。
答案 0 :(得分:0)
我装配了这个批处理文件,以帮助快速测试Nest API读/写和OAuth协商。对不起它有点乱,但希望它有所帮助。您需要下载curl包并指向它。同样在pastebin。保存为.bat
并根据需要评论/取消注释rem
行。
@echo off
set curl_path=c:\nest\curl
set client_pin=[you get this from the provided URL on the client page]
set client_id=[you get this from the client page]
set client_secret=[you get this from the client page]
set access_token=[you'll get this from a successful oauth]
rem set new_url=https://firebase-apiserver02-tah01-iad01.dapi.production.nest.com:9553
rem TOGGLE FOR AUTH
rem set GET_AUTH=true
rem TOGGLE FOR AUTH
rem TOGGLE FOR DEAUTH
set GET_DEAUTH=true
rem TOGGLE FOR DEAUTH
rem TOGGLE FOR GET
rem set GET_DATA=true
rem TOGGLE FOR GET
rem TOGGLE FOR SET
rem set SET_DATA=true
rem TOGGLE FOR SET
rem TOGGLE FOR STREAM
rem set STREAM_DATA=true
rem TOGGLE FOR STREAM
rem DEVICE_CONFIG
rem virtual:
set dev_id1=[manually enter example devid]
rem real:
set dev_id2=
set dev_id=%dev_id1%
rem DEVICE_CONFIG_END
rem VALUE_CONFIG
set value1=target_temperature_f
set value2=name
set value3=hvac_mode
set value4=ambient_temperature_f
set value5=target_temperature_high_f
set value_name=%value3%
set new_int_value=77
set new_string_value=heat
set new_value=%new_string_value%
rem VALUE_CONFIG_END
rem STRUCT_CONFIG
set struct1=devices
set struct2=structures
set struct3=metadata
set struct4=devices/thermostats
set struct4=devices/smoke_co_alarms
set struct4=devices/company
set struct_name=%struct2%
rem STRUCT_CONFIG_END
set url=https://developer-api.nest.com/%struct_name%.json?auth=%access_token%
set url_by_id=%new_url%/devices/thermostats/%dev_id%.json?auth=%access_token%
set url_by_value=%new_url%/devices/thermostats/%dev_id%/%value_name%.json?auth=%access_token%
set header=Content-Type: application/json
rem GET_DATA
set get_struct=curl\curl.exe -k -L %url%
set get_by_id=curl\curl.exe -k -L %url_by_id%
set get_by_value=curl\curl.exe -k -L %url_by_value%
set get_url=%get_by_id%
rem GET_DATA_END
rem OAUTH
rem set oauth=curl\curl.exe -k -i -v -X POST -d "code=%client_pin%&client_id=%client_id%&client_secret=%client_secret%&grant_type=authorization_code" https://api.home.nest.com/oauth2/access_token
set oauth=curl\curl.exe -k -i -v -X POST "https://api.home.nest.com/oauth2/access_token?code=%client_pin%&client_id=%client_id%&client_secret=%client_secret%&grant_type=authorization_code"
rem SET_DATA
rem set change_num=curl\curl.exe -k -i -L -X PUT %url_by_value% -H "Content-Type: application/json; charset=UTF-8" -d "%new_int_value%"
rem set change_text=curl\curl.exe -k -i -L -X PUT "%url_by_value%" -H "%header%" -d '"%new_string_value%"'
rem set change_text=curl\curl.exe -k -i -L -X PUT -H "Content-Type: application/json; charset=UTF-8" -d "{"%value_name%":%new_value%}" %url_by_id%
rem set change_text=curl\curl.exe -k -i -L -X PUT "%url_by_value%" -H "%header%" -d '"%new_value%"'
rem THIS WORKS:
rem set change_text=curl\curl.exe -k -L -X PUT "https://developer-api.nest.com/devices/thermostats/%dev_id%?auth=%access_token%" -H "Content-Type: application/json" -d "{\"hvac_mode\":\"heat\"}"
rem set stream=curl\curl.exe -k -i -v -L -X GET -H "Accept: application/json" -H "Accept: text/event-stream" -H "Keep-Alive: 60" -H "Connection: keep-alive" "https://firebase-apiserver02-tah01-iad01.dapi.production.nest.com:9553/?auth=[FILL IN AUTH_TOKEN]"
set deauth=curl\curl.exe -k -i -v -L -X DELETE "https://api.home.nest.com/oauth2/access_tokens/%access_token%"
set set_data=%change_text%
echo.
if defined GET_AUTH %oauth%
if defined GET_AUTH echo.
if defined GET_DEAUTH %deauth%
if defined GET_DEAUTH echo.
if defined GET_DATA echo %get_url%
if defined GET_DATA echo.
if defined GET_DATA %get_url%
if defined GET_DATA echo.
if defined SET_DATA echo %set_data%
if defined SET_DATA echo.
if defined SET_DATA %set_data%
if defined SET_DATA echo.
if defined STREAM_DATA %stream%
if defined STREAM_DATA echo.
goto end_com
- To **change** the specific structure to away. The value here is a string so be sure to include the single quotes:
curl -v -L -X PUT "https://developer-api.nest.com/structures/<STRUCTURE ID>/away?auth=<AUTH_TOKEN>" -H "Content-Type: application/json" -d '"away"'
:end_com
goto end_com2
echo %curl_path%
echo %client_pin%
echo %client_id%
echo %client_secret%
echo %access_token%
:end_com2