slacker775/tesla-api

PHP版的Tesla API库

0.1.0 2020-01-05 22:42 UTC

This package is auto-updated.

Last update: 2024-09-06 09:17:43 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支持