我正在研究 Smartsheet API,但我不是专业人士。我需要一些帮助才能从一张特定的表格中获取所有信息。对于所有信息,我指的是所有列和它们的所有附件。我还需要帮助才能将附件下载到用户设备。有没有人在 PHP 中使用模板?到目前为止,我已经从列中获取信息,但这还不够。
$baseURL = "https://api.smartsheet.com/1.1";
$sheetsURL = $baseURL. "/sheets/";
$getSheetURL = $baseURL. "/sheet/xxx";
$rowsURL = $baseURL. "/sheet/xxx/rows";
$rowAttachmentsURL = $baseURL. "/sheet/3712544801089412/row/{{ROWID}}/attachments";
$getAttachmentURL = $baseURL ."/sheet/3712544801089412/attachment/{{ATTACHMENTID}}";
// Insert your Smartsheet API Token here
$accessToken = "xxx";
// Create Headers Array for Curl
$headers = array(
"Authorization: Bearer ". $accessToken,
"Content-Type: application/json"
);
// Connect to Smartsheet API to get Selected Sheet
$curlSession = curl_init($getSheetURL);
curl_setopt($curlSession, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, TRUE);
$getSheetResponseData = curl_exec($curlSession);
$sheetObj = json_decode($getSheetResponseData);
//attachment
echo "<h1>Sheet name: ". $sheetObj->name ."</h1>";
echo "<br>";
//table start
echo "<table>";
echo "<td>"."Attachment"."</td>";
foreach ($sheetObj->columns as $column) {
echo "<td>".$column->title ."</td>";
}
echo "<tr>";
foreach ($sheetObj->rows as $row) {
$curlSession = curl_init($rowAttachmentsURL);
curl_setopt($curlSession, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, TRUE);
$getAttachmentsResponse = curl_exec($curlSession);
// Assign response to variable
$attachments = json_decode($getAttachmentsResponse);
$rowAttachmentsURL = str_replace('{{ROWID}}', $row->id, $rowAttachmentsURL);
var_dump($attachments);
foreach ($row->attachments as $attachment) {
echo "<td>".$attachment->name."</td>";
}
foreach ($row->cells as $cell)
{
echo "<td>".$cell->value."</td>";
}
echo "<td></td><td></td><td></td>";
echo "</tr>";
}
echo "</table>";
curl_close($curlSession);
?>