Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google cloud platform CreateAssessment()上的Google.Cloud.RecaptchaEnterprise错误;请求包含无效的参数";_Google Cloud Platform_Google Cloud Functions_Recaptcha_Captcha_Recaptcha Enterprise - Fatal编程技术网

Google cloud platform CreateAssessment()上的Google.Cloud.RecaptchaEnterprise错误;请求包含无效的参数";

Google cloud platform CreateAssessment()上的Google.Cloud.RecaptchaEnterprise错误;请求包含无效的参数";,google-cloud-platform,google-cloud-functions,recaptcha,captcha,recaptcha-enterprise,Google Cloud Platform,Google Cloud Functions,Recaptcha,Captcha,Recaptcha Enterprise,我正在尝试使用Google.Cloud.RecaptchaEnterprise库来验证客户获得的新企业密钥的captcha请求 string _siteKey = ConfigurationManager.AppSettings["GoogleCaptcha.CheckboxCaptcha.SiteKey"]; string _apiKey = ConfigurationManager.AppSettings["GoogleCaptcha.ApiKey"]

我正在尝试使用Google.Cloud.RecaptchaEnterprise库来验证客户获得的新企业密钥的captcha请求

string _siteKey = ConfigurationManager.AppSettings["GoogleCaptcha.CheckboxCaptcha.SiteKey"];
string _apiKey = ConfigurationManager.AppSettings["GoogleCaptcha.ApiKey"];
string _projectId = ConfigurationManager.AppSettings["GoogleCaptcha.ProjectId"];
string recaptchaAction = "CreateAccountAssessment";
try {
    var appPath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
    string credential_path = appPath + "googlecredentials.json";
    System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", credential_path);

    RecaptchaEnterpriseServiceClient client =
    RecaptchaEnterpriseServiceClient.Create();

    CreateAssessmentRequest createAssessmentRequest = new CreateAssessmentRequest()
    {
        Assessment = new Assessment()
        {
            Event = new Event()
            {
                SiteKey = _siteKey,
                Token = formResponse,
                ExpectedAction = "Create_Account"
            },
            Name = recaptchaAction,                         
        },
        Parent = _projectId
    };

    Assessment response = client.CreateAssessment(createAssessmentRequest);

    if (response.TokenProperties.Valid == false)
    {
        Sitecore.Diagnostics.Log.Error("The CreateAssessment() call failed " +
            "because the token was invalid for the following reason: " +
            response.TokenProperties.InvalidReason.ToString(), this);

        return "Invalid captcha.";
    }
    else
    {
        if (response.Event.ExpectedAction == recaptchaAction)
        {
            Sitecore.Diagnostics.Log.Error("The reCAPTCHA score for this token is: " +
                response.RiskAnalysis.Score.ToString(), this);

            return "";
        }
        else
        {
            Sitecore.Diagnostics.Log.Error("The action attribute in your reCAPTCHA " +
                "tag does not match the action you are expecting to score", this);

            return "Invalid captcha.";

        }

    }
}
catch (Exception ex)
{
    Sitecore.Diagnostics.Log.Error("Error validating captcha on " + _url + "; " + ex.Message, this);
    return "Unable to connect to captcha service.";
}
据我所知,我的所有属性都是正确的,但它在
Assessment response=client.CreateAssessment(createAssessmentRequest)上抛出了一个错误

状态(StatusCode=“InvalidArgument”,Detail=“请求包含无效参数。”,DebugException=“Grpc.Core.Internal.corererrorDetailexception:{”已创建“@1621287236.280000000”,“描述”:“从对等ipv6接收到的错误:[2607:f8b0:4006:81a::200a]:443”,“文件”:“T:\src\github\Grpc\workspace\u csharp\u ext\u windows\u x64\src\Core\lib\surface\call.cc“,“文件行”:1062,“grpc消息”:“请求包含无效参数。”,“grpc状态”:3}”)


我强烈怀疑问题(或至少是一个问题)是请求的
父属性

发件人:

将在其中创建评估的项目名称,格式为“projects/{project}”

…而我怀疑您的项目ID只是ID,而不是以“projects/”开头的资源名称

我建议尽可能使用生成的资源名称类以及相应的属性

CreateAssessmentRequest CreateAssessmentRequest=新建CreateAssessmentRequest
{
评估=新评估
{
事件=新事件
{
SiteKey=\u SiteKey,
Token=formResponse,
ExpectedAction=“创建账户”
},
Name=recaptchaAction,
},
ParentAsProjectName=新项目名(_projectId)
};

您的怀疑是正确的,我只是使用了父ID,而不是“projects/{projectId}”。现在尝试一下。。。