# Realtime en async

Ontvang resultaten in de respons, of een baan indienen en later ophalen. Kies hoe uw applicatie of agent wacht op werk.

Canonische referentie: https://flashdata.dev/nl/docs/reference/realtime-and-async
Beoordeeld: 2026-11-04 door FlashData

<a id="choose"></a>

## Een verzoekmodus kiezen

Google Search en YouTube Data ondersteunen beide modi. YouTube Download vereist async, Batch of Bulk; het ondersteunt geen realtime. De bronparameters blijven hetzelfde bij het overschakelen van realtime naar async.

| Modus | Gebruiken wanneer | Wat u ontvangt |
| --- | --- | --- |
| Realtime | Een zoekresultaat is nodig in de huidige interactie. | Het resultaat body in dezelfde HTTP respons. |
| Async | Het werk moet worden voortgezet nadat uw proces is verbroken, of u downloadt media. | Een taak ID onmiddellijk; de status en resultaten afzonderlijk ophalen. |

### Levenscyclus aanvragen

```text
Realtime POST data.flashdata.dev/v1/queries/realtime → resultaten
Async POST data.flashdata.dev/v1/queries → job ID
          GET api.flashdata.dev/v2/jobs/{id} → status
          GET api.flashdata.dev/v2/jobs/{id}/results → resultaten
```

- [Veel vragen?](https://flashdata.dev/nl/docs/reference/batch-and-bulk/reference.md)

<a id="submit"></a>

## Een verzoek versturen

Stel FLASHDATA_API_KEY in op een sleutel die google_search toelaat. Kies real-time of async; elke inzending draait één factureerbare zoekopdracht. Houd scripts, ontvangstbewijzen en resultaten in dezelfde nieuwe werkmap.

Python voorbeelden gebruiken Python 3.10+ en Verzoeken. Elk script draait onafhankelijk en leest opgeslagen bestanden van eerdere stappen. De cURL alternatieve behoeften Bash, cURL 7.76+ en jq.

### Python · eenmaal installeren

```bash
python3 -m pip install requests
```

- [API sleutel en headers](https://flashdata.dev/nl/docs/guides/headers-and-authentication/reference.md)
- [Google Search-parameters](https://flashdata.dev/nl/docs/sources/google_search/reference.md)

<a id="realtime"></a>

### Realtime: krijg het resultaat nu

POST /v1/queries/realtime geeft status: done en een resultaatarray terug. Lees result.json; er is geen peiling nodig.

#### Python

Sla op als realtime.py en voer python3 realtime.py uit.

##### realtime.py

```python
import json
import os
from pathlib import Path

import requests

response = requests.post(
    "https://data.flashdata.dev/v1/queries/realtime",
    headers={"X-API-Key": os.environ["FLASHDATA_API_KEY"]},
    json={"source": "google_search", "query": "battery recycling research", "params": {"num": 5}},
    timeout=120, allow_redirects=False,
)
response.raise_for_status()
result = response.json()
Path("result.json").write_text(json.dumps(result, indent=2), encoding="utf-8")
print(json.dumps(result, indent=2))
```


#### cURL / Bash

##### Ontvang het resultaat · cURL / Bash

```bash
curl --fail-with-body --silent --show-error \
  'https://data.flashdata.dev/v1/queries/realtime' \
  --header "X-API-Key: ${FLASHDATA_API_KEY:?Set FLASHDATA_API_KEY}" \
  --header 'Content-Type: application/json' \
  --data '{"source":"google_search","query":"battery recycling research","params":{"num":5}}' \
  --output result.json &&
jq '{source, status, results, usage}' result.json
```



<a id="async"></a>

### Async: bewaar een vacaturebevestiging

POST /v1/queries retourneert een lopende sollicitatie, niet de zoekresultaten. Bewaar submission.json en ga verder met de status en resultaatverzoeken hieronder.

#### Python

Sla op als submit_async.py en voer python3 submit_async.py uit.

##### submit_async.py

```python
import json
import os
from pathlib import Path

import requests

response = requests.post(
    "https://data.flashdata.dev/v1/queries",
    headers={"X-API-Key": os.environ["FLASHDATA_API_KEY"]},
    json={"source": "google_search", "query": "battery recycling research", "params": {"num": 5}},
    timeout=30, allow_redirects=False,
)
response.raise_for_status()
result = response.json()
Path("submission.json").write_text(json.dumps(result, indent=2), encoding="utf-8")
print(json.dumps(result, indent=2))
```

##### Ontvangstvelden · afgekort voorbeeld

```json
{
  "id": "job_EXAMPLE",
  "source": "google_search",
  "status": "pending"
}
```


#### cURL / Bash

##### Verzend en bewaar de taak ID · cURL / Bash

```bash
curl --fail-with-body --silent --show-error \
  'https://data.flashdata.dev/v1/queries' \
  --header "X-API-Key: ${FLASHDATA_API_KEY:?Set FLASHDATA_API_KEY}" \
  --header 'Content-Type: application/json' \
  --data '{"source":"google_search","query":"battery recycling research","params":{"num":5}}' \
  --output submission.json &&
jq '{id, source, status, links}' submission.json
```

##### Ontvangstvelden · afgekort voorbeeld

```json
{
  "id": "job_EXAMPLE",
  "source": "google_search",
  "status": "pending"
}
```



<a id="status"></a>

## Controleer een async-taak

Lees job.status met de ID in submission.json. Wacht voor in behandeling of verwerking op de Retry-After-vertraging voordat u opnieuw controleert; Python drukt het af en cURL slaat het op in status-headers.txt. Back-off gebruiken als er geen hint terug wordt gegeven. Een succesvolle statusaanvraag betekent niet dat de job is voltooid.

| job.status | Volgende actie |
| --- | --- |
| pending / processing | Wacht, controleer dan opnieuw dezelfde taak ID. |
| completed | Het opgeslagen resultaat ophalen. |
| failed | Lees job.error. Repareer de oorzaak voordat u nieuw werk indient. |

### Python

Sla op als job_status.py en voer python3 job_status.py uit.

#### job_status.py

```python
import json
import os
from pathlib import Path

import requests

job_id = json.loads(Path("submission.json").read_text(encoding="utf-8"))["id"]
response = requests.get(
    f"https://api.flashdata.dev/v2/jobs/{job_id}",
    headers={"X-API-Key": os.environ["FLASHDATA_API_KEY"]},
    timeout=30, allow_redirects=False,
)
response.raise_for_status()
Path("job.json").write_text(json.dumps(response.json(), indent=2), encoding="utf-8")
print(json.dumps(response.json()["job"], indent=2))
print("Retry-After:", response.headers.get("Retry-After", "not provided"))
```


### cURL / Bash

#### Lees status · cURL / Bash

```bash
JOB_ID=$(jq -er '.id' submission.json)
curl --fail-with-body --silent --show-error \
  "https://api.flashdata.dev/v2/jobs/$JOB_ID" \
  --header "X-API-Key: ${FLASHDATA_API_KEY:?Set FLASHDATA_API_KEY}" \
  --dump-header status-headers.txt --output job.json &&
jq '.job | {id, source, status, error}' job.json
```



<a id="results"></a>

## Het voltooide resultaat ophalen

Voer dit uit nadat job.status is voltooid. Het standaard resultaat antwoord is 302: Locatiepunten naar een ondertekende opslag URL. De twee onderstaande verzoeken houden uw API-sleutel op FlashData en bewaren de originele JSON op result.json. Voor YouTube Download beschrijft deze JSON de media die naar uw opslag worden geleverd; het is niet het video- of audiobestand.

### Python

Sla op als job_result.py en voer python3 job_result.py uit.

#### job_result.py

```python
import json
import os
from pathlib import Path

import requests

receipt = json.loads(Path("submission.json").read_text(encoding="utf-8"))
job_id = receipt["id"]
response = requests.get(
    f"https://api.flashdata.dev/v2/jobs/{job_id}/results",
    headers={"X-API-Key": os.environ["FLASHDATA_API_KEY"]},
    timeout=30, allow_redirects=False,
)
response.raise_for_status()
if response.status_code != 302:
    raise RuntimeError(f"Expected a result redirect, got {response.status_code}")
url = response.headers["Location"]
if not url.startswith("https://"):
    raise ValueError("Expected an HTTPS storage URL")

# A separate request: no FlashData key is sent to storage.
result = requests.get(url, timeout=120)
result.raise_for_status()
data = result.json()  # Requests automatically decodes Content-Encoding: gzip.
Path("result.json").write_text(json.dumps(data, indent=2), encoding="utf-8")
print(json.dumps(data, indent=2))
```


### cURL / Bash

#### Originele JSON · cURL / Bash ophalen

```bash
JOB_ID=$(jq -er '.id' submission.json)
RESULT_URL=$(curl --fail-with-body --silent --show-error \
  "https://api.flashdata.dev/v2/jobs/$JOB_ID/results" \
  --header "X-API-Key: ${FLASHDATA_API_KEY:?Set FLASHDATA_API_KEY}" \
  --output /dev/null --write-out '%{redirect_url}') &&
curl --fail-with-body --silent --show-error --compressed --proto '=https' \
  "${RESULT_URL:?Expected a signed result URL}" --output result.json &&
jq '{source, status, results, usage}' result.json
```


- [JSON, tekst- en Markdown-formaten](https://flashdata.dev/nl/docs/guides/response-formats/reference.md#completed-results)
- [Opslaginstellingen downloaden](https://flashdata.dev/nl/docs/guides/youtube-download-guide/reference.md)

<a id="recovery"></a>

## Vertragingen en storingen verwerken

| Situatie | Wat je moet doen |
| --- | --- |
| Indiening is verlopen | Een POST kan al geaccepteerd zijn. Controleer uw opgeslagen ontvangstbewijs en account geschiedenis voordat opnieuw in te dienen; herhaalde POST's kunnen nieuwe factureerbare banen te creëren. |
| 409 · result_not_ready | Blijf peilen. Maak geen andere job aan. |
| 422 · result_not_ready | De baan is mislukt. Lees job.error voordat u het opnieuw probeert. |
| 429 | Eer Retry-After of retry_after; verminder het indieningspercentage wanneer de capaciteit vol is. |
| 410 · result_expired | Opgeslagen resultaten verlopen 24 uren na voltooiing. Gebruik je bewaarde kopie. |

- [Fouten en statuscodes](https://flashdata.dev/nl/docs/errors/reference.md)
- [CLI, polling en webhook walkthrough](https://flashdata.dev/nl/docs/guides/async-batch/reference.md)
