1

我正在开发一个 Basecamp 小部件,它必须显示有关我们当前正在处理的项目的重要信息。由于我找不到有关此问题的任何相关且详细的文档,因此我想向社区寻求帮助。

我的情况

我目前已经在回应我的项目,这些数据包含:

  • 项目名称
  • 描述
  • 项目编号

对于我的待办事项,我回显了以下数据:

  • 剩余的待办事项
  • 已完成的待办事项
  • 待办事项总数
  • 百分比进展

我的目标

我想展示在每个单独项目中工作的所有人的头像。由于这种编程对我来说是相当新的,所以我很感激关于这个问题的一些指导。由于 Basecamp 变得越来越流行,我认为更多的人可能会对这些信息感兴趣。我已经查阅了 Basecamp 的 API 并写了一小部分来尝试响应项目成员的呼应,但徒劳无功。

我提前感谢您的帮助。

干杯,

(帖子脚本:这是我到目前为止的完整来源,一些值被故意更改以隐藏凭据等数据。对不起,很长的帖子,我尽量保持简短)

身份验证和检索项目数据

$appName = 'MyAppName';
$appContact = 'MyAddress';

$basecampAccountId = 'MyAccountID';
$basecampUsername = 'MyBaseCampUsername';
$basecampPassword = 'MyPassword';
$baseUrl = "https://basecamp.com/************/api/v1";

$url= $baseUrl.'/projects.json';
$credentials = "$basecampUsername:$basecampPassword";
$helloHeader = "User-Agent: $appName ($appContact)";

$ch = curl_init($url);
    curl_setopt($ch, CURLOPT_USERPWD, $credentials);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);     //optional
    curl_setopt($ch, CURLOPT_MAXREDIRS, 3);             //optional
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);     //optional
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);        //optional
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);       //optional
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);

    curl_setopt($ch, CURLOPT_HTTPGET, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array($helloHeader));

    $response = curl_exec($ch);
    $errno = curl_errno($ch);
    $error = curl_error($ch);
    curl_close($ch);

检索待办事项列表

$json = $response;
$data = json_decode($json);

/*echo "<br/><br/>";*/

foreach($data as $key)
{   
    echo "<ul>";
    echo "<li>".$key->name."</li>";
    echo "<li>".$key->id."</li>";
    echo "<li>".$key->description."</li>";

    $url= $baseUrl.'/projects/'.$key->id.'/todolists.json';
$ch = curl_init($url);
    curl_setopt($ch, CURLOPT_USERPWD, $credentials);
    // curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);     //optional
    curl_setopt($ch, CURLOPT_MAXREDIRS, 3);             //optional
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);     //optional
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);        //optional
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);       //optional
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);

    curl_setopt($ch, CURLOPT_HTTPGET, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array($helloHeader));

    $response = curl_exec($ch);
    $errno = curl_errno($ch);
    $error = curl_error($ch);
    curl_close($ch);

    // print_r($response);

    $json = $response;
    $data = json_decode($json);

    $todo_remain = $data[0]->remaining_count;
    $todo_completed = $data[0]->completed_count;
    $todo_total = $todo_remain + $todo_completed;

    echo "<BR>";
    echo "<BR>";
    echo "Remaining To-Do Items:";
    echo "<BR>";
    echo $todo_remain;
    echo "<BR>";
    echo "Completed To-Do Items:";
    echo "<BR>";
    echo $todo_completed;
    echo "<BR>";
    echo "Total To-Do Items:";
    echo "<BR>";
    echo $todo_total;
    echo "<BR>";
    echo "Remaining percentage is: <BR>";
    echo round(($todo_remain/$todo_total)*100);
    echo "%";
    echo "<BR>";
    echo "Completed percentage is: <BR>";
    echo round(($todo_completed/$todo_total)*100);
    echo "%";


    echo "</ul>";
4

0 回答 0