function fetchAndReturnResults(
BatchJobServiceClient $batchJobServiceClient,
string $batchJobResourceName
) {
$results = [];
// Gets all the results from running batch job and print their information.
try{
$batchJobResults = $batchJobServiceClient->listBatchJobResults(
$batchJobResourceName,
['pageSize' => self::PAGE_SIZE, "responseContentType"=>2]
);
foreach ($batchJobResults->iterateAllElements() as $batchJobResult) {
$results[] = $batchJobResult;
}
return $results;
}
catch(GoogleAdsException $googleAdsException){
foreach ($googleAdsException->getGoogleAdsFailure()->getErrors() as $error) {
$results['error'][] = ['status'=>$error->getErrorCode()->getErrorCode(), 'err'=> $error->getMessage()];
}
}
catch(Exception $e){
$results['error'][] = ['status'=>$e->getCode(), 'err'=>$e->getMessage()];
}
finally {
return $results;
}
}