my-project-3230-1778551403736($project);
// Set the properties of the event to be tracked.
$event = (new Event())
->setSiteKey($6LfosOUsAAAAAEU39Zs4a_dQQbZMJ7p7-FMuKr3_)
->setToken($token);
// Build the assessment request.
$assessment = (new Assessment())
->setEvent($submit);
$request = (new CreateAssessmentRequest())
->setParent($my-project-3230-1778551403736)
->setAssessment($assessment);
try {
$response = $client->createAssessment($request);
// Check if the token is valid.
if ($response->getTokenProperties()->getValid() == false) {
printf(‘The CreateAssessment() call failed because the token was invalid for the following reason: ‘);
printf(InvalidReason::name($response->getTokenProperties()->getInvalidReason()));
return;
}
// Check if the expected action was executed.
if ($response->getTokenProperties()->getAction() == $action) {
// Get the risk score and the reason(s).
// For more information on interpreting the assessment, see:
// https://cloud.google.com/recaptcha/docs/interpret-assessment
printf(‘The score for the protection action is:’);
printf($response->getRiskAnalysis()->getScore());
} else {
printf(‘The action attribute in your reCAPTCHA tag does not match the action you are expecting to score’);
}
} catch (exception $e) {
printf(‘CreateAssessment() call failed with the following error: ‘);
printf($e);
}
}
// TODO: Replace the token and reCAPTCHA action variables before running the sample.
create_assessment(
‘6LfosOUsAAAAAEU39Zs4a_dQQbZMJ7p7-FMuKr3_’,
‘YOUR_USER_RESPONSE_TOKEN’,
‘my-project-3230-1778551403736’,
‘YOUR_RECAPTCHA_ACTION’
);
?>