UNLOCK API

ドラッグ&ドロップ解決API

ドラッグ&ドロップのタスクをAPIに送ると、コードがページに送信する回答が返ってきます。画像と、ピースを置く位置。受け取るもの: 実行する移動(移動元と移動先の座標)。

概要

1,000件あたりの料金
$0.60 (1タスク $0.0006)
createTaskのtype
DragAndDropTask
in.phpのmethod
送信するもの
画像と、ピースを置く位置
受け取るもの
実行する移動(移動元と移動先の座標)

値の見つけ方

背景とピースを、指示をcommentとして添えて送信します。

createTaskとgetTaskResult

タスクを作成し、約5秒待ってから、statusがreadyになるまで5秒ごとに結果を確認します。タスクが失敗した場合はAPIがエラーを返し、料金は残高に戻ります。

import time, requests

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

task = requests.post(f"{API}/createTask", json={
    "clientKey": KEY,
    "task": {
      "type": "DragAndDropTask",
      "body": "/9j/4AAQSkZJRgABAQ...",
      "comment": "Move each piece to its matching place"
    }
}).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")

APIリファレンス全文: すべてのパラメータとsolutionオブジェクト