# APIクイックスタート

コールセンター Google Search とりあえず YouTube API を直接オーバー HTTP. JSONの応答を1つ送信し、要求して下さい;SDKは要求しません。

キャニシニカル参照: https://flashdata.dev/ja/docs/guides/http-quickstart
レビュー: FlashData による 2026-11-04

<a id="application"></a>

## HTTP リクエストを初めて作成

APIキーを設定し、保存した応答を1つGoogle検索して検査します。


<a id="prepare"></a>

### 認証

アカウントを作成し、メールを検証し、Google Search 権限でキーを作成します。 既存のキーを再利用できます。

ターミナルで実行し、入力内容が表示されないプロンプトにキーを貼り付けます。FLASHDATA_API_KEY が設定済みなら、この手順は不要です。

#### Bash

##### キーを設定

```bash
# Bash: paste the key into a hidden prompt, not into this command.
read -r -s -p "FlashData API key: " FLASHDATA_API_KEY
printf '\n'
export FLASHDATA_API_KEY
```


#### PowerShell 7

##### キーを設定

```powershell
# PowerShell 7: paste the key into a hidden prompt.
$flashdataSecureKey = Read-Host "FlashData API key" -AsSecureString
$env:FLASHDATA_API_KEY = [System.Net.NetworkCredential]::new("", $flashdataSecureKey).Password
Remove-Variable flashdataSecureKey
```


- [アカウントを作成](https://flashdata.dev/signup)
- [API Keys を開く](https://flashdata.dev/app/api-keys)
- [エージェント認証](https://flashdata.dev/auth.md)

<a id="curl"></a>

### 検索を実行

クライアントを選択し、同じターミナルで例を実行します。 https://data.flashdata.dev/v1/queries/realtime に POST リクエストを 1 つ送信し、JSON を印刷します。 X-API-Keyで認証; JSONをContent-Typeで送信: application/json.

#### cURL

cURL 7.76+ · Bash お問い合わせ Linux, macOS または Git Bash. ペーストして実行します。

##### 検索・Bash / cURL

```bash
curl --fail-with-body --silent --show-error --max-time 70 \
  --request POST https://data.flashdata.dev/v1/queries/realtime \
  --header "X-API-Key: $FLASHDATA_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
  "source": "google_search",
  "query": "battery recycling research",
  "params": {
    "num": 5
  }
}'
```


#### PowerShell 7

PowerShell 7+ · このネイティブPowerShellコマンドを貼り付けます。

##### 検索・PowerShell

```powershell
$flashdataRequest = '{"source":"google_search","query":"battery recycling research","params":{"num":5}}'
$flashdataSearch = @{
  Uri = 'https://data.flashdata.dev/v1/queries/realtime'
  Method = 'Post'
  Headers = @{ 'X-API-Key' = $env:FLASHDATA_API_KEY }
  ContentType = 'application/json'
  Body = $flashdataRequest
  TimeoutSec = 70
  MaximumRedirection = 0
  SkipHttpErrorCheck = $true
  ErrorAction = 'Stop'
}
$flashdataResponse = Invoke-WebRequest @flashdataSearch
$flashdataResponse.Content
if ($flashdataResponse.StatusCode -ge 400) {
  throw "HTTP $($flashdataResponse.StatusCode). Inspect the response above before retrying."
}
```


#### JavaScript

Node.js 22+ · search.mjsとして保存し、ローカルまたはサーバー上で実行します。 組み込みフェッチを使用。npmはインストールしません。

##### search.mjs

```javascript
const key = process.env.FLASHDATA_API_KEY;
if (!key) throw new Error("Set FLASHDATA_API_KEY in this terminal.");

let response;
try {
  response = await fetch("https://data.flashdata.dev/v1/queries/realtime", {
    method: "POST",
    redirect: "error",
    signal: AbortSignal.timeout(70000),
    headers: { "X-API-Key": key, "Content-Type": "application/json" },
    body: JSON.stringify({"source":"google_search","query":"battery recycling research","params":{"num":5}}),
  });
} catch {
  throw new Error("Request did not complete. Check History before resubmitting.");
}

const body = await response.text();
console.log(body); // Print the full response before checking its status.
if (!response.ok) {
  const retryAfter = response.headers.get("retry-after");
  throw new Error("HTTP " + response.status + ". See the response above." +
    (retryAfter ? " Retry-After: " + retryAfter : ""));
}
let result;
try {
  result = JSON.parse(body);
} catch {
  throw new Error("Expected JSON. Inspect the response above and the API URL.");
}
if (!result || result.error === true || result.status !== "done" || !Array.isArray(result.results)) {
  throw new Error("Query did not succeed. Inspect status and error in the response above.");
}
```

##### 実行・JavaScript

```bash
node search.mjs
```


#### Python

Python 3.10+ · search.pyとして保存します。 標準ライブラリのみで、pipはインストールしません。 Python コマンドの場合、python3 または py -3 を使用します。

##### search.py

```python
import json
import os
import urllib.error
import urllib.request

key = os.environ.get("FLASHDATA_API_KEY")
if not key:
    raise SystemExit("Set FLASHDATA_API_KEY in this terminal.")

# Do not forward the API key to a redirect destination.
class NoRedirect(urllib.request.HTTPRedirectHandler):
    def redirect_request(self, req, fp, code, msg, headers, newurl):
        return None

request = urllib.request.Request(
    "https://data.flashdata.dev/v1/queries/realtime",
    data=json.dumps({"source":"google_search","query":"battery recycling research","params":{"num":5}}).encode("utf-8"),
    headers={"X-API-Key": key, "Content-Type": "application/json"},
    method="POST",
)
try:
    with urllib.request.build_opener(NoRedirect).open(request, timeout=70) as response:
        body = response.read().decode("utf-8")
except urllib.error.HTTPError as error:
    print(error.read().decode("utf-8", errors="replace"))
    retry_after = error.headers.get("Retry-After")
    raise SystemExit("HTTP " + str(error.code) + ". See the response above." +
                     (" Retry-After: " + retry_after if retry_after else ""))
except (urllib.error.URLError, TimeoutError):
    raise SystemExit("Request did not complete. Check History before resubmitting.")

print(body)  # The run command saves this full response to result.json.
try:
    result = json.loads(body)
except json.JSONDecodeError:
    raise SystemExit("Expected JSON. Inspect the response above and the API URL.")
if (not isinstance(result, dict) or result.get("error") is True
        or result.get("status") != "done" or not isinstance(result.get("results"), list)):
    raise SystemExit("Query did not succeed. Inspect status and error in the response above.")
```

##### 実行・Python

```bash
python -X utf8 search.py
```



<a id="result"></a>

### 結果を確認

HTTPの成功とstatus: doneを確認します。 results[].organicのソースタイトル、リンク、スニペット、およびusage.creditsの料金を読みます。

status: doneで空の結果やオーガニックリストは、有効な空の結果です。

| フィールド | 利用する |
| --- | --- |
| status | "done"は、クエリが正常に終了していることを確認します。 |
| results[0].organic[] | 結果検索 インデックス化前の結果が非空であることを確認します。 |
| title / link / snippet | ソースのタイトル、URLおよびexcerpt。 |
| usage.credits | このクエリで課金された実際のクレジット。 |

#### 応答例

```json
{
  "source": "google_search",
  "status": "done",
  "results": [
    {
      "organic": [
        {
          "title": "Battery recycling research",
          "link": "https://example.org/recycling",
          "snippet": "An example search excerpt."
        }
      ]
    }
  ],
  "usage": {
    "credits": 0.02
  }
}
```


<a id="diagnostics"></a>

## デバッグのための応答を保存

次の意図したリクエストをキャプチャするには、上記のcURLコマンドにこれらのオプションを追加します。 失敗したリクエストを再試行するために決定する前にファイルを調べます。

### cURL

```bash
--dump-header response-headers.txt --output result.json
```

- [HTTPのエラーと回復](https://flashdata.dev/ja/docs/errors/reference.md)

<a id="check"></a>

## アクセスとクレジットの確認

これらのGETは、クエリクレジットを使用せずに、アイデンティティ、残高、価格を読み取ります。 HTTP 200を期待し、有料の作業を提出する前に、以下のフィールドを確認してください。

口座の読み込み: https://api.flashdata.dev/v2. データ要求: https://data.flashdata.dev/v1. 両方使用X-API-Key; JSON POST リクエストは Content-Type: application/json.

| フィードバック | 応答で確認するべきこと |
| --- | --- |
| identity | accountId、access: "ready"、"google_search"を含むスコープ、expiresAtのスコープを確認します。 accountTypeは、"owned"で、所有者のキーまたは"temporary"のトライアルキーです。 |
| balance | availableCredits を読んで下さい。 このアカウントのすべてのキーは、同じ残高を使用します。 |
| pricing | 価格[0]については、ソースがgoogle_searchであり、利用可能なのはtrueです。 requestCount の estimatedCredits を比較して下さい: availableCredits が付いている 1。 提出前に価格と残高が変更できます。 |

### Bash / cURL

#### 無料チェック・Bash

```bash
(
for endpoint in 'identity' 'balance' 'pricing?source=google_search&request_count=1'; do
  printf '\n%s\n' "$endpoint"
  curl --fail-with-body --silent --show-error --max-time 20 \
    --header "X-API-Key: $FLASHDATA_API_KEY" \
    --write-out '\nHTTP %{http_code}\n' \
    "https://api.flashdata.dev/v2/api-access/$endpoint" || exit
done
)
```


### PowerShell 7

#### 無料チェック・PowerShell

```powershell
try {
  foreach ($flashdataPath in @('identity', 'balance', 'pricing?source=google_search&request_count=1')) {
    Write-Host $flashdataPath
    $flashdataRead = @{
      Uri = "https://api.flashdata.dev/v2/api-access/$flashdataPath"
      Headers = @{ 'X-API-Key' = $env:FLASHDATA_API_KEY }
      TimeoutSec = 20
      MaximumRedirection = 0
      ErrorAction = 'Stop'
    }
    Invoke-RestMethod @flashdataRead | ConvertTo-Json -Depth 20
  }
} catch {
  throw
}
```



<a id="next"></a>

## 次のステップ

- [Google Searchベストプラクティス](https://flashdata.dev/ja/docs/guides/google-search-guide/reference.md)
- [YouTube Data](https://flashdata.dev/ja/docs/guides/youtube-data-guide/reference.md)
- [YouTube Download](https://flashdata.dev/ja/docs/guides/youtube-download-guide/reference.md)
- [API リファレンス](https://flashdata.dev/ja/docs/api-reference/reference.md)
- [OpenAPI 仕様](https://flashdata.dev/docs/openapi.json)

<a id="troubleshooting"></a>

## ステップが失敗した場合

端末で印刷された応答をお読みください。 JavaScript とりあえず Python レポート HTTP エラーとエラー Retry-After へ へ へ へ stderr. 各例は一度に提出します。自動的に再試行しません。

| シンプトム | 次のアクション |
| --- | --- |
| コマンドの欠落またはサポートされていないオプション | 選択した例で必要なバージョンを確認してください。 利用条件 PowerShell 7 ではなく、 Windows PowerShell 5.1、または使用 Bash とりあえず cURL 7.76+. JavaScriptはNode 22+を必要とします; Pythonは3.10+を要求します。 正式なダウンロードページから欠落したランタイムをインストールし、ターミナルを再開し、再びキーを設定します。 |
| ミスキー/401 | このプロセスでFLASHDATA_API_KEYを設定し、再び身元確認を行います。 ベアラープレフィックスなしで、フルアクティブのAPIキーを供給します。 有効期限が切れたり、再発した場合は、現在の認証された資格を使用してください。チャットに貼り付けないでください。 |
| 403 | インフォメーション identity.scopes のための google_search そして準備ができたアクセス。 所有者から欠落した権限を要求し、要求のソースを変更すると、アクセスを許可しません。 |
| 402 | 残高を再度読み、現在の価格と比較します。 Billing をレビューできます。 試行錯誤は、主張による所有者のアクセスを必要とします。 交換試験を作成することは回復しません。 |
| 400 / 422 | 返されたエラーメッセージを読みます。 正確なデータホスト、POSTメソッド、Content-Type、JSONフィールド名を確認してください。 まっすぐな引用符および数字 params.num を使用して下さい、それから拒絶された要求を訂正して下さい。 |
| 429 | Retry-Afterを現時点で尊重する。そうしないと、バインドされたバックオフを使用し、対立性を低下させる。 急激にループしないように、新しいキーを作成したり、別のトライアルを登録したりして制限を迂回したりしないでください。 |
| HTTP 200 の失敗した状態か間違い | ボディの間違いを読んで、あらゆる要求か仕事IDを維持して下さい。 パースされた JSON ボディを成功させたり、自動的にそれを取除いないで下さい。 |
| 空の結果 | ステータスが終わったら、認証が機能しました。 空の結果を保持するか、新しい有料リクエストとしてより広範なクエリを試してください。 |
| JSONの代りのタイムアウト、関係の損失、5xxかHTML | POSTは、その応答が失われても受け入れられるかもしれません。 History を元のクエリでチェックし、返送前に返された IDs を保存します。 無料GETチェックが取得できます。 URL は、Web サイトのホストではなく data.flashdata.dev を使用し、TLS の検証を無効にしないことを確認します。 |

- [リクエスト履歴](https://flashdata.dev/app/jobs)
- [キーの管理](https://flashdata.dev/app/api-keys)
- [cURLのダウンロード](https://curl.se/download.html)
- [PowerShellをインストールする](https://learn.microsoft.com/powershell/scripting/install/installing-powershell)
- [Node.jsのダウンロード](https://nodejs.org/en/download)
- [Pythonのダウンロード](https://www.python.org/downloads/)
