Skip to content

Commit 7883360

Browse files
committed
Add OAuth documentation
1 parent c2f1373 commit 7883360

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,41 @@ asyncio.run(main())
3737
## TeslaFleetOAuth
3838
This extends TeslaFleetApi to support OAuth, and requires a client_id, and either a refresh_token or initial authentication code.
3939

40+
```
41+
import json
42+
43+
async def main():
44+
with open("auth.json", "r") as f:
45+
auth = json.load(f)
46+
async with aiohttp.ClientSession() as session:
47+
api = TeslaFleetOAuth(
48+
session,
49+
client_id=<client_id>,
50+
access_token=auth["access_token"],
51+
refresh_token=auth["refresh_token"],
52+
expires=auth["expires"],
53+
region="na",
54+
raise_for_status=True,
55+
)
56+
try:
57+
data = await api.vehicle.list()
58+
print(data)
59+
except TeslaFleetError.Base as e:
60+
print(e.message, e.error)
61+
62+
with open("auth.json", "w") as f:
63+
json.dump(
64+
{
65+
"access_token": api.access_token,
66+
"refresh_token": api.refresh_token,
67+
"expires": api.expires,
68+
},
69+
f,
70+
)
71+
72+
asyncio.run(main())
73+
```
74+
4075
## Teslemetry
4176
This extends TeslaFleetApi to send requests through Teslemetry, which manages all aspects of Tesla OAuth. This class only requires an access_token from the Teslemetry console.
4277

0 commit comments

Comments
 (0)