> ## Documentation Index
> Fetch the complete documentation index at: https://docs.omocaptcha.com/llms.txt
> Use this file to discover all available pages before exploring further.

# RecaptchaV2TokenTask

> reCAPTCHA-v2 còn được gọi là captcha TÔI KHÔNG PHẢI ROBOT, reCAPTCHA là một loại hình ảnh xác thực rất phổ biến.

<Frame>
  <img src="https://mintcdn.com/omocaptcha/Jc1mwaiUF23R0W3R/images/recaptcha-v2-token.png?fit=max&auto=format&n=Jc1mwaiUF23R0W3R&q=85&s=e612b6b98669ec8b3de004d009329242" alt="reCAPTCHA v2 - I'm not a robot" width="616" height="164" data-path="images/recaptcha-v2-token.png" />
</Frame>

Đầu tiên, bạn cần tìm giá trị của tham số `data-sitekey` trong mã nguồn của trang web. Mở **DevTools** trong trình duyệt và tìm phần tử có thuộc tính `data-sitekey`:

```html theme={null}
<div id="recaptcha-demo"
     class="g-recaptcha"
     data-sitekey="6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-"
     data-callback="onSuccess"
     data-action="action">
```

## 1. Tạo yêu cầu

### Request

```http theme={null}
POST https://api.omocaptcha.com/v2/createTask
Content-Type: application/json
```

#### Body Parameters

| Tham số           | Kiểu     | Bắt buộc | Mô tả                                                                                                                                                                                              |
| ----------------- | -------- | :------: | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `clientKey`       | `String` |     ✅    | Khóa tài khoản khách hàng                                                                                                                                                                          |
| `task.type`       | `String` |     ✅    | Tên class dịch vụ captcha cần giải                                                                                                                                                                 |
| `task.websiteURL` | `String` |     ✅    | Địa chỉ của một trang web đích. Có thể được đặt ở bất kỳ đâu trên trang web, ngay cả trong khu vực thành viên. Nhân viên của chúng tôi không điều hướng đến đó mà thay vào đó mô phỏng chuyến thăm |
| `task.websiteKey` | `String` |     ✅    | Khoá trang web Recaptcha. Tìm hiểu cách tìm nó trong bài viết này.                                                                                                                                 |

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.omocaptcha.com/v2/createTask \
    -H "Content-Type: application/json" \
    -d '{
      "clientKey": "OMO_API_KEY",
      "task": {
        "type": "RecaptchaV2TokenTask",
        "websiteURL": "https://lessons.zennolab.com/captchas/recaptcha/v2_simple.php?level=high",
        "websiteKey": "6Lcg7CMUAAAAANphynKgn9YAgA4tQ2KI_iqRyTwd"
      }
    }'
  ```

  ```javascript Node.js theme={null}
  const res = await fetch("https://api.omocaptcha.com/v2/createTask", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      clientKey: "OMO_API_KEY",
      task: {
        type: "RecaptchaV2TokenTask",
        websiteURL: "https://lessons.zennolab.com/captchas/recaptcha/v2_simple.php?level=high",
        websiteKey: "6Lcg7CMUAAAAANphynKgn9YAgA4tQ2KI_iqRyTwd"
      }
    })
  });
  console.log(await res.json());
  ```

  ```python Python theme={null}
  import requests

  res = requests.post(
      "https://api.omocaptcha.com/v2/createTask",
      json={
          "clientKey": "OMO_API_KEY",
          "task": {
              "type": "RecaptchaV2TokenTask",
              "websiteURL": "https://lessons.zennolab.com/captchas/recaptcha/v2_simple.php?level=high",
              "websiteKey": "6Lcg7CMUAAAAANphynKgn9YAgA4tQ2KI_iqRyTwd"
          }
      }
  )
  print(res.json())
  ```

  ```php PHP theme={null}
  <?php
  $ch = curl_init("https://api.omocaptcha.com/v2/createTask");
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
      "clientKey" => "OMO_API_KEY",
      "task" => [
          "type" => "RecaptchaV2TokenTask",
          "websiteURL" => "https://lessons.zennolab.com/captchas/recaptcha/v2_simple.php?level=high",
          "websiteKey" => "6Lcg7CMUAAAAANphynKgn9YAgA4tQ2KI_iqRyTwd"
      ]
  ]));
  echo curl_exec($ch);
  ```
</CodeGroup>

### Response

<CodeGroup>
  ```json Thành công theme={null}
  {
    "errorId": 0,
    "taskId": "49f9f60a-c809-4af0-93c0-0409b72e67e0"
  }
  ```

  ```json Thất bại theme={null}
  {
    "errorId": 1,
    "errorCode": "",
    "errorDescription": ""
  }
  ```
</CodeGroup>

* `errorId = 0` và `taskId` → thành công
* `errorId = 1` và `errorCode` → thất bại (tra [Bảng mã lỗi](/vi/api/bang-ma-loi))

## 2. Nhận kết quả yêu cầu

### Request

```http theme={null}
POST https://api.omocaptcha.com/v2/getTaskResult
Content-Type: application/json
```

```json theme={null}
{
  "clientKey": "OMO_API_KEY",
  "taskId": "49f9f60a-c809-4af0-93c0-0409b72e67e0"
}
```

### Response

<CodeGroup>
  ```json Thành công theme={null}
  {
    "errorId": 0,
    "status": "ready",
    "solution": {
      "gRecaptchaResponse": "3AHJ_VuvYIBNBW5yyv0zRYJ75VkOKvhKj9_xGBJKnQimF72rfoq3Iy-DyGHMwLAo6a3"
    }
  }
  ```

  ```json Đang xử lý theme={null}
  {
    "status": "processing",
    "errorId": 0,
    "errorCode": "",
    "errorDescription": ""
  }
  ```

  ```json Thất bại theme={null}
  {
    "errorId": 1,
    "errorCode": "ERROR_JOB_STATUS",
    "errorDescription": "Job failed",
    "status": "fail",
    "solution": {}
  }
  ```
</CodeGroup>

* `errorId = 0` & `status = "ready"` → đọc token trong `solution.gRecaptchaResponse`
* `errorId = 0` & `status = "processing"` → đang xử lý, **chờ 2 giây** rồi thử lại
* `errorId = 1` → thất bại, tra `errorCode` trong [Bảng mã lỗi](/vi/api/bang-ma-loi)

<Tip>
  Trong DevTools, tìm `<textarea name="g-recaptcha-response">` và đặt token nhận được vào đó, sau đó nhấn nút **Check** / submit form.
</Tip>
