我正在尝试集成 google recaptcha 企业,我已经从控制台成功生成了站点密钥 api 密钥,我遇到了两个问题
在 Web 视图中加载“我不是机器人”复选框 UI 时,出现“无效域名”错误
我捆绑了模拟 html,然后将其加载到 webView 中,这是我的 html 文件代码
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="https://www.google.com/recaptcha/enterprise.js" async defer></script> </head> <body> <div class="g-recaptcha" data-sitekey="site_key"></div> </body> </html>
在创建评估时,这是集成过程的第二步,我得到以下响应
请检查评估请求
let urlString = String(format: "https://recaptchaenterprise.googleapis.com/v1beta1/projects/%@/assessments?key=%@", projectID, apiKey) var parameters = [String: Any]() parameters = ["event":["token": token, "siteKey": siteKey, "expectedAction": "other" ]] let headers: HTTPHeaders = [ "Content-Type": "application/json" ] let request = Alamofire.request(urlString, method: method, parameters: parameters, encoding: JSONEncoding.default, headers: headers) NSLog("Sending request to \(request.request?.url?.absoluteString ?? "")") request.validate() request.responseJSON { response in switch response.result { case .success: print("success case ") if response.result.error != nil { completion(false, response.result.error! as! String) } completion(true, result) case .failure(let error): print("failure case ") completion(false, (response.result.error?.localizedDescription)!) break } }
并获得评估 api 的以下响应
{ "error": { "code": 403, "message": "Requests from this iOS client application <empty> are blocked.", "status": "PERMISSION_DENIED", "details": [ { "@type": "type.googleapis.com/google.rpc.ErrorInfo", "reason": "API_KEY_IOS_APP_BLOCKED", "domain": "googleapis.com", "metadata": { "consumer": "projects/some_id", "service": "recaptchaenterprise.googleapis.com" } } ] } }
我怎样才能解决这两个问题?