Harvest API-PHP- 跟踪给定时间范围内的总小时数

Harvest API-PHP-Tracking total hours for a given time frame

我需要使用 Harvest API 输出给定时间范围内的总小时数。我已经在 PHP 中编码,但它给出了一个错误 Call to undefined method HarvestAPI::getUsersActiveTimer() 输入是 开始日期 结束日期 输出 总时数

这是我的代码

     <?php
    require_once( dirname(__FILE__) . '/HarvestAPI.php' );

    spl_autoload_register(array('HarvestAPI', 'autoload') );

    $api = new HarvestAPI();
    $api->setUser( $user );
    $api->setPassword( $password );
    $api->setAccount( $account_name );

    $api->setSSL( true );

    $result = $api->getUsersActiveTimer( $userid );

    if( $result->isSuccess() ) {
    echo "It is Successful!";
        if( ! is_null( $result->data ) ){
            echo $result->get( "started-at" );
        }
    }

else{
echo "It is not Successful";

}

?>

请提出解决此问题的方法

如果您查看 Harvest API here,您会发现没有名为 getUsersActiveTimer 的方法。这可能来自旧版本。您可以使用 getUserEntries 方法 "get all user entries for given time range and for a particular project if specified." 这可能需要在 PHP 内进行一些额外的计算,但它是一种有效的方法,因此它应该 return 一些数据。您将需要指定一个日期范围。这是文档中的一个用法示例:

$range = new Harvest_Range( "20090712", "20090719" );
 $project_id = 12345;
 $user_id = 11111;

 $api = new HarvestAPI();

 $result = $api->getUserEntries( $user_id, $range, $project_id );
 if( $result->isSuccess() ) {
     $dayEntries = $result->data;
     var_dump($dayEntries);
 } else {
  //no data!
}