首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tesla API (非官方)-通过cURL进行测试

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

Stack Overflow用户
提问于 2019-05-17 22:52:30
回答 1查看 1.7K关注 0票数 0

在针对Tesla API编写任何实际代码之前,我想我应该使用一些cURL命令来熟悉它。已经在挣扎了。只是尝试通过以下方式取回oauth令牌:

代码语言:javascript
复制
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'

产生以下错误:

代码语言:javascript
复制
{"error":"invalid_client","error_description":"Client authentication failed due to unknown client, no client authentication included, or unsupported authentication method."}

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-18 03:44:40

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

代码语言:javascript
复制
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查询:

代码语言:javascript
复制
curl --request GET --header 'Authorization: Bearer 32819532809859320539205djfdsjfkdsd' 'https://owner-api.teslamotors.com/api/1/vehicles'

然后:

代码语言:javascript
复制
curl --request GET --header 'Authorization: Bearer 32819532809859320539205djfdsjfkdsd' 'https://owner-api.teslamotors.com/api/1/vehicles/?id=0123456789'
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56188898

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档