Tesla API(非官方)-通过cURL进行测试

twh00eeo  于 2022-11-13  发布在  其他
关注(0)|答案(2)|浏览(426)

在编写任何针对Tesla API的实际代码之前,我想我应该破解一些cURL命令来熟悉一下。我已经很吃力了。只是想通过以下方式取回一个oauth令牌:

curl -X POST  -H 'Content-Type: application/json' -d '{"grant_type": "password", "client_id": "81527cff06843c838fe1e431c2ef2106796384", "client_secret": "c7257eb71a564034f9419ee651c7d0e5f7aa6bfbd18bafb5c5c033b093bb2fa3", "email": "myemail@email.com","password": "mypassword"}' 'https://owner-api.teslamotors.com/oauth/token'

产生以下错误:

{"error":"invalid_client","error_description":"Client authentication failed due to unknown client, no client authentication included, or unsupported authentication method."}

我怀疑可能是在https://tesla-api.timdorr.com/api-basics/authentication上共享的client_id和client_secret被撤销了,但是当我尝试注册一个给我一个不同的对的smartcar帐户时,这对我也不起作用。

tzdcorbm

tzdcorbm1#

这个命令可以正常工作,我只是在复制/粘贴它的时候把client_id搞砸了。在这里留下正确的版本,以防其他人想绕过Tesla API。

curl -X POST  -H 'Content-Type: application/json' -d '{"grant_type": "password", "client_id": "81527cff06843c8634fdc09e8ac0abefb46ac849f38fe1e431c2ef2106796384", "client_secret": "c7257eb71a564034f9419ee651c7d0e5f7aa6bfbd18bafb5c5c033b093bb2fa3", "email": "myemail@email.com","password": "mypassword"}' 'https://owner-api.teslamotors.com/oauth/token'

然后使用收到的令牌进行get查询:

curl --request GET --header 'Authorization: Bearer 32819532809859320539205djfdsjfkdsd' 'https://owner-api.teslamotors.com/api/1/vehicles'

然后道:

curl --request GET --header 'Authorization: Bearer 32819532809859320539205djfdsjfkdsd' 'https://owner-api.teslamotors.com/api/1/vehicles/?id=0123456789'
ewm0tg9j

ewm0tg9j2#

我编写了这些简单的python脚本来访问具有最新需求的tesla api,这些脚本可以用来让任何人开始使用api。
https://github.com/Marky0/tesla_api_lite

相关问题