UNLOCK API
Trascina e rilascia

Trascina e rilascia

Come inviare un task Trascina e rilascia a UNLOCK API con createTask o in.php: nomi dei tipi di task, tutti i parametri, l'oggetto solution, i campi proxy ed esempi di codice in 7 linguaggi.
Prezzo
$0.60 $0.0006 per task
Invii
Le immagini e dove vanno i pezzi
Ricevi
Spostamenti da eseguire (punti di partenza e di arrivo)

Panoramica e prezzo

Nomi dei tipi di task

Questo tipo ha un solo nome.
DragAndDropTask

Oggetto task

type
StringObbligatorio
Nome del tipo di task. Maiuscole e minuscole sono indifferenti. DragAndDropTask
body
StringObbligatorio
L'immagine in base64 (JPG, PNG o GIF), fino a circa 100 KB. Il prefisso data: è ammesso.
comment
StringFacoltativo
Istruzione per il risolutore, ad esempio la domanda mostrata sopra l'immagine.

I campi non elencati qui vengono passati al risolutore così come sono stati inviati.

Richiesta

POST /createTask
{
  "clientKey": "YOUR_API_KEY",
  "task": {
    "type": "DragAndDropTask",
    "body": "/9j/4AAQSkZJRgABAQ...",
    "comment": "Move each piece to its matching place"
  }
}

Oggetto solution

Restituito in solution quando status è ready.
answer
Array
La risposta da inviare.
POST /getTaskResult
{
  "errorId": 0,
  "taskId": 1001,
  "status": "ready",
  "solution": {
    "answer": [
      {
        "from": {
          "x": 20,
          "y": 40
        },
        "to": {
          "x": 210,
          "y": 44
        }
      }
    ]
  },
  "cost": "0.0006",
  "createTime": 1791640000,
  "endTime": 1791640014,
  "solveCount": 1
}

Esempi di codice

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")

Metodo form in.php

Questo tipo è disponibile solo con i metodi JSON.