1

我需要使用 Harvest API 输出给定时间范围内的总小时数。我已经用 PHP 编码,但它给出了错误调用未定义的方法 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";

}

?>

请建议一种解决方法

4

1 回答 1

1

如果您在这里查看 Harvest API,您会发现没有调用方法getUsersActiveTimer。这可能来自旧版本。您可以使用getUserEntries“获取给定时间范围内的所有用户条目以及特定项目(如果已指定)”的方法。这可能需要在 PHP 中进行一些额外的计算,但它是一种有效的方法,因此它应该返回一些数据。您需要指定日期范围。这是文档中的一个使用示例:

$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!
}
于 2016-04-08T22:18:32.537 回答