desync/tesla-api

PHP 的 Tesla API 库

1.0.0 2020-04-06 17:41 UTC

This package is auto-updated.

Last update: 2024-09-08 08:43:13 UTC


README

PHP 的 Tesla API

此软件包提供了一个易于使用的 Tesla(指汽车/太阳能制造商)API 客户端。通过此 API,您可以查询车辆状态、配置等。

基本用法

获取 OAuth 令牌

    $apiClient = Client::create();
    $clientId = '81527cff06843c8634fdc09e8ac0abefb46ac849f38fe1e431c2ef2106796384';
    $clientSecret = 'c7257eb71a564034f9419ee651c7d0e5f7aa6bfbd18bafb5c5c033b093bb2fa3';
    $email = 'joe@example.com';
    $password = 'password';

    $auth = new CreateAccessTokenRequest();
    $auth->setClientId($clientId)
        ->setClientSecret($clientSecret)
        ->setEmail($email)
        ->setPassword($password)
        ->setGrantType('password');

    $authResponse = $apiClient->createOauthToken($auth);
    printf("Token = %s\n", $authResponse->getAccessToken());

使用 API

    $token = 'xxxxxx';

    $httpClient = Client::createHttpClient($token, new HttpJournal());
    $apiClient = Client::create($httpClient);

    $vehicles = $apiClient->getVehicles();
    dump($vehicles);

待办事项

  • 通过 league/oauth2-client 添加适当的 OAuth2 支持