在根据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帐户时,也对我不起作用。
答案 0 :(得分:0)
嗯,此命令可以正常工作,我只是在复制/粘贴客户端时搞砸了client_id。如果其他人想curl缩特斯拉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'