UNLOCK API
画像グリッド

画像グリッド

createTaskまたはin.phpでUNLOCK APIに画像グリッドタスクを送信する方法です。タスクの種類名、すべてのパラメータ、solutionオブジェクト、プロキシフィールド、7言語のコードサンプルを掲載しています。
料金
$0.36 1タスク $0.00036
送信するもの
base64形式のグリッド画像と指示(例: 選択する物体)
受け取るもの
クリックするセルの番号

概要と料金

タスクの種類名

この種類の名前は1つだけです。
GridTask

別名: GridTaskProxyless

taskオブジェクト

type
String必須
タスクの種類名です。大文字と小文字は区別しません。 GridTask
body
String必須
base64の画像(JPG、PNG、GIF)で、約100 KBまでです。data:プレフィックスを付けても構いません。
comment
String任意
ソルバーへの指示です。例: 画像の上に表示される質問。
rows
Integer任意
グリッドの行数です。
columns
Integer任意
グリッドの列数です。
imgType
String任意
画像の種類です(わかっている場合)。
previousId
String任意
最初の答えのあとにグリッドが変わった場合、前のタスクのidです。
canSkip
Boolean任意
一致するタイルがないという答えがありうる場合はtrueです。

ここにないフィールドは、送信されたままソルバーに渡されます。

リクエスト

POST /createTask
{
  "clientKey": "YOUR_API_KEY",
  "task": {
    "type": "GridTask",
    "body": "/9j/4AAQSkZJRgABAQ...",
    "comment": "Select all squares with traffic lights",
    "rows": 3,
    "columns": 3
  }
}

solutionオブジェクト

statusがreadyのとき、solutionに入って返されます。
click
Array
クリックするタイルの番号です。1から数え、左から右、上から下の順です。
POST /getTaskResult
{
  "errorId": 0,
  "taskId": 1001,
  "status": "ready",
  "solution": {
    "click": [
      1,
      4,
      9
    ]
  },
  "cost": "0.00036",
  "createTime": 1791640000,
  "endTime": 1791640014,
  "solveCount": 1
}

コードサンプル

import time, requests

API = "https://unlock-api.com"
KEY = "YOUR_API_KEY"

task = requests.post(f"{API}/createTask", json={
    "clientKey": KEY,
    "task": {
      "type": "GridTask",
      "body": "/9j/4AAQSkZJRgABAQ...",
      "comment": "Select all squares with traffic lights",
      "rows": 3,
      "columns": 3
    }
}).json()
if task["errorId"]:
    raise SystemExit(task["errorCode"])

for _ in range(60):   # 60 x 5 s = the 5 minute task limit
    time.sleep(5)
    r = requests.post(f"{API}/getTaskResult", json={"clientKey": KEY, "taskId": task["taskId"]}).json()
    if r["errorId"]:
        raise SystemExit(f"{r['errorCode']}: {r.get('errorDescription', '')}")   # failed tasks are refunded
    if r["status"] == "ready":
        print(r["solution"])
        break
else:
    raise SystemExit("timed out")

in.phpフォームメソッド

同じタスクを従来のフォームリクエストで送る方法です。res.phpが答えをテキストで返します。
in.php, res.php
curl -s "https://unlock-api.com/in.php" -d "key=YOUR_API_KEY&method=base64&recaptcha=1&textinstructions=Select+all+traffic+lights&body=BASE64_IMAGE&json=1"
# {"status":1,"request":"1001"}

curl -s "https://unlock-api.com/res.php?key=YOUR_API_KEY&action=get&id=1001&json=1"
# {"status":0,"request":"CAPCHA_NOT_READY"}  then  {"status":1,"request":"ANSWER"}

フォームAPI: in.phpとres.php