There is a script deployed to Google Script which is bound to Google Cloud project and is published/deployed as API executable. All credentials from Google Cloud are in place.
public function runCreateDriveScript($clientName, $orderName)
{
$scriptId = env('GOOGLE_SCRIPT_ID');
$service = $this->getService();
$request = new \Google_Service_Script_ExecutionRequest();
$request->setFunction('main');
$request->setParameters(["fdf"]);
try {
$response = $service->scripts->run($scriptId, $request);
if ($response->getError()) {
$error = $response->getError()['details'][0];
printf("Script error message: %s
", $error['errorMessage']);
if (array_key_exists('scriptStackTraceElements', $error)) {
print "Script error stacktrace:
";
foreach ($error['scriptStackTraceElements'] as $trace) {
printf("\t%s: %d
", $trace['function'], $trace['lineNumber']);
}
}
}
} catch (\Exception $e) {
// The API encountered a problem before the script started executing.
echo 'Caught exception: ', $e->getMessage(), "
";
}
}
Caught exception: { "error": { "code": 403, "message": "The caller does not have permission", "errors": [ { "message": "The caller does not have permission", "domain": "global", "reason": "forbidden" } ], "status": "PERMISSION_DENIED" } }
What am I missing? What should I do in order to call Google Script by API? Is there a good manual on that topic?