k-ko/discovergy-oauth1

Discovergy OAUTH 1.0 API 客户端

v3.3.2 2022-05-19 06:58 UTC

This package is auto-updated.

Last update: 2024-09-19 12:04:30 UTC


README

PHP 类用于建立 OAuth1 会话并访问 Discovergy API

基本用法

use Exception;
use Discovergy\API1 as DiscovergyAPI;

try {
    $api = new DiscovergyAPI(
        // Required parameters
        $client,     // Your own application identifier
        $identifier, // Login for the Discovergy portal, mostly your email address
        $secret
    );

    // Use cache, system temp dir.
    $api->setCache(true);
    // Use your own cache dir.
    $api->setCache('/path/to/your/cache/dir');
    // If cache is used, default TTL is 1 day

    // Cache for 1 hour
    $api->setTTL(3600);

    // Authorize
    $api->init();
} catch (Exception $e) {
    die($e->getMessage());
}

API 类在 API 上进行授权,并在出错时尝试最多 5 次。

使用 $api 实例,您现在可以查询数据。

目前实现了 GET 端点(通过 __call()

元数据

  • /devices
  • /field_names

测量

  • /readings
  • /last_reading
  • /statistics
  • /load_profile
  • /raw_load_profile

分解

  • /disaggregation
  • /activities

网站访问代码

  • /website_access_code

虚拟表计

  • /virtual_meters

命名约定是:端点 /snake_case 必须按照 getCamelCase() 调用。

getMeters() 是分开的,具有延迟加载和文件缓存。

所有方法都期望与在 API 文档 中描述的相同的必要(和可选)参数。

因此,调用必须是

$last_reading = $api->getMeter('YOUR-METER-ID')->getLastReading();

具有可选参数的调用将是

例如,端点 /readings 期望一个 resolution

$readings = $api->getMeter('YOUR-METER-ID')->getReadings([ 'resolution' => $resolution, 'from' => $from ]);