27.01.2022, 09:24
(27.01.2022, 07:26)admin Wrote: Refresh token is what you use to get a new access and refresh token pair. Access token is used for API calls. It might have already expired so you need to generate a new token pair.
You will need a scheduled script to refresh the token periodically. See this for more info: https://tesla-api.timdorr.com/api-basics...cess-token
i changed the code a little bit, but always received a deny from the webservice
Code:
function GetToken()
body = json.encode({
grant_type = 'authorization_code',
client_id = 'ownerapi',
refresh_token = refreshToken,
scope = 'openid email offline_access'
})
resp = {}
res, code, headers = http.request({
url = 'https://auth.tesla.com/oauth2/v3/token',
method = 'POST',
source = ltn12.source.string(body),
sink = ltn12.sink.table(resp),
headers = {
['Content-Type'] = 'application/json',
['Accept'] = 'application/json',
['Content-Length'] = #body
}
})
log(res, code, headers)
end
As refreshToken i used the Refresh Token from the Auth for Tesla app.
When i hardcoded the Access Token in the code it works, but this code expires in 8 hours
Code:
function GetToken()
return accessToken --from the Auth for Tesla app
end