我正在使用PHP SDK生成Google Presentation(包含50多张幻灯片的模板),最近当我使用方法 replaceAllShapeWithImage 时,需要很长时间才能抛出其中一篇论文消息:
错误消息1:
{ “错误”:{ “代码”:500, “message”:“遇到内部错误。”, “错误”:[ { “message”:“遇到内部错误。”, “域名”:“全球”, “reason”:“backendError” } ] “状态”:“内部” } }
错误消息2:
{ “错误”:{ “代码”:503, “message”:“该服务目前无法使用。”, “错误”:[ { “message”:“该服务目前无法使用。”, “域名”:“全球”, “reason”:“backendError” } ] “状态”:“无法使用” } }
以下是一些要测试的代码:
function replaceAllShapeWithImageT(array &$requests, $objectId, $image_url, $replace_mothod ='CENTER_CROP')
{
$requests[] = new Google_Service_Slides_Request(array(
'replaceAllShapesWithImage' => array(
'imageUrl' => $image_url,
'imageReplaceMethod' => $replace_mothod,
'containsText' => array(
'text' => $objectId,
'matchCase' => true
)
)
));
}
function testGenBatch($client)
{
echo "\n STart";
$slidesService = new Google_Service_Slides($client);
$presentationCopyId ='SLIDE_ID';
$requests = [];
replaceAllShapeWithImageT($requests, '{{destination_image}}', "https://picsum.photos/1400/800?image=1076");
replaceAllShapeWithImageT($requests, '{{client_logo}}', "https://picsum.photos/400/200?image=1069");
replaceAllShapeWithImageT($requests, '{{country_image}}', "https://picsum.photos/1400/800?image=1073");
replaceAllShapeWithImageT($requests, '{{hotel_0_thumb}}', "https://picsum.photos/900/500");
replaceAllShapeWithImageT($requests, '{{hotel_1_image_1}}', "https://picsum.photos/1400/800?image=1079");
replaceAllShapeWithImageT($requests, '{{hotel_1_image_2}}', "https://picsum.photos/1400/800?image=1080");
replaceAllShapeWithImageT($requests, '{{hotel_1_image_3}}', "https://picsum.photos/1400/800?image=1082");
$batchUpdateRequest = new Google_Service_Slides_BatchUpdatePresentationRequest(array(
'requests' => $requests
));
try {
echo "\n Launch BAtch Request\n";
$response = $slidesService->presentations->batchUpdate($presentationCopyId, $batchUpdateRequest);
// var_dump($response);
echo "\n DOOOOOOOOOOOOOOOOOOOOOONE\n";
} catch(\Exception $e) {
echo "\nErrooor : ".$e->getMessage()."\n====================================================\n";
}
}
谢谢