I am trying to update the chart dynamically that is embedded in a Google Slides, but it throws an error at me.
This is the function that I came up with to replace some specific text that is placed in my base Google slide.
public function getGoogleDrivePdf($fileId, $substitutions)
{
$client = $this->getGoogleClient();
$driveService = new Google_Service_Drive($client);
$slidesService = new Google_Service_Slides($client);
$copy = new Google_Service_Drive_DriveFile([
'name' => $substitutions['student_name'] . ' presentation',
]);
$driveResponse = $driveService->files->copy($fileId, $copy);
$slideFileId = $driveResponse->id;
$requests = [];
foreach ($substitutions as $key => $value) {
$requests[] = new Google_Service_Slides_Request(
[
'replaceAllText' => [
'containsText' => [
'text' => '{{'.$key.'}}',
'matchCase' => true
],
'replaceText' => $value
]
]
);
}
$batchUpdateRequest = new Google_Service_Slides_BatchUpdatePresentationRequest([
'requests' => $requests,
]);
$updateResponse = $slidesService->presentations->batchUpdate($slideFileId, $batchUpdateRequest);
$response = $driveService->files->export(
$slideFileId,
'application/pdf',
[
'alt' => 'media',
]
);
$content = $response->getBody()->getContents();
$driveService->files->delete($slideFileId);
// Download
$response = new Response();
$response->headers->set('Content-Type', 'application/pdf');
$response->headers->set('Content-Disposition', 'attachment; filename="' . $substitutions['slide_filename'] . '"');
$response->setContent($content);
return $response;
}
This function replaces the text I want that are in the Google Slide and downloads the slide as a PDF file without an issue.
But, now I want to add a chart to the slide and change the chart values dynamically. I tried to accomplish this by changing the values in source Google Sheet to replaceable text but It throws me this error.
{
“error”: {
“code”: 400,
“message”: “Invalid value at ‘requests[9].replace_all_text.replace_text’ (TYPE_STRING), 10nInvalid value at ‘requests[10].replace_all_text.replace_text’ (TYPE_STRING), 20nInvalid value at ‘requests[11].replace_all_text.replace_text’ (TYPE_STRING), 30nInvalid value at ‘requests[12].replace_all_text.replace_text’ (TYPE_STRING), 40nInvalid value at ‘requests[13].replace_all_text.replace_text’ (TYPE_STRING), 50nInvalid value at ‘requests[14].replace_all_text.replace_text’ (TYPE_STRING), 50nInvalid value at ‘requests[15].replace_all_text.replace_text’ (TYPE_STRING), 50nInvalid value at ‘requests[16].replace_all_text.replace_text’ (TYPE_STRING), 50”,
“errors”: [……..
Any idea how to fix this or any workarounds?