在谷歌应用程序脚本中,我编写以下代码来读取谷歌表单的响应
function formResponse()
{
var form = FormApp.openById('form-id');
var formResponses = form.getResponses();
for (var i = 0; i < formResponses.length; i++)
{
var formResponse = formResponses[i];
var itemResponses = formResponse.getItemResponses();
for (var j = 0; j < itemResponses.length; j++)
{
var itemResponse = itemResponses[j];
Logger.log('Response #%s to the question "%s" was "%s"',
(i + 1).toString(),
itemResponse.getItem().getTitle(),
itemResponse.getResponse());
}
}
return formResponses;
}
在谷歌应用程序脚本日志已成功输入我所期望的内容。
在PHP中,我使用以下代码调用Google应用程序脚本。
$accessToken = $client->authenticate($request->input('code'));
$client->setAccessToken($accessToken);
$service = new Google_Service_Script($client);
$scriptId = 'MIQpTICu_Gobs7BEB-v3lHZZMYprHmXMAQrb';
// Create an execution request object.
$request = new Google_Service_Script_ExecutionRequest();
$request->setFunction('formResponse');
$responses = $service->scripts->run($scriptId, $request);
$resp = $responses->getResponse();
print_r($resp);
它不会获得任何表单响应值
我返回表单响应而不是返回数组对象。