我目前正在从事一个类似的项目,这是我到目前为止所拥有的,也许它会帮助你:
检索项目数据
$appName = 'AppName';
$appContact = 'MyAddress';
$basecampAccountId = 'MyAccountID';
$basecampUsername = 'MyUsername';
$basecampPassword = 'MyPassword';
$baseUrl = "https://basecamp.com/XXXXXXXXXX/api/v1";
$url= $baseUrl.'/projects.json';
$credentials = "$basecampUsername:$basecampPassword";
$helloHeader = "User-Agent: $appName ($appContact)";
/*echo $url.'<br>'; //Echoes the url of the imported projects
/*echo $credentials.'<br>';*/ //Echoes the credentials of the person signed in
/*echo $helloHeader.'<br>';*/ //Echoes the email address of the person signed in
$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);
检索待办事项列表项
$todo = $response;
$todophp = json_decode($todo);
echo "$response";
echo "<br/><br/>";
print_r(array_values($todophp));
echo "<br/><br/>";
foreach($todophp as $tododata)
{
echo "<ul>";
echo "<li>".$tododata->name."</li>";
echo "<li>".$tododata->id."</li>";
echo "<li>".$tododata->description."</li>";
/*echo "<li>".$tododata->;*/
$url= $baseUrl.'/projects/'.$tododata->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);
$todo = $response;
$todophp = json_decode($todo);
$todo_remain = $todophp[0]->remaining_count;
$todo_completed = $todophp[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>";
}
让我知道 ;) 祝你好运玩得开心(不要忘记更改凭据等)