Belgeleri incele
Başlarken
Google Search ve YouTube API'leri doğrudan HTTP üzerinde arayın. Bir istek gönderin ve JSON yanıtını okuyun; SDK gerekli değildir.
Kimlik Doğrulama
Bir hesap oluşturun, e-postanızı doğrulayın ve Google Search izni ile anahtar oluşturun. Mevcut bir anahtarı yeniden kullanabilirsiniz.
Terminalde çalıştırın ve anahtarı gizli giriş istemine yapıştırın. FLASHDATA_API_KEY zaten ayarlıysa bu adımı atlayın.
Anahtarınızı ayarlayın# 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_KEYAnahtarınızı ayarlayın# 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 flashdataSecureKeyArama çalıştırın
Bir müşteri seçin ve aynı terminalde örneği çalıştırın. Her biri bir tane gönderir POST İstek istemek https://data.flashdata.dev/v1/queries/realtime Baskılar ve baskılar JSON. Kimlikle X-API-KeyGönder; JSON with with with ile Content-Type: application/json.
cURL 7.76+ · Bash Onda Linux, macOS veya veya veya Git Bash. Paste ve koşmak.
Arama · Bash / cURLcurl --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+ · Bu yerli PowerShell komutunu yapıştırın.
Arama · 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." }Node.js 22+ · search.mjs olarak tasarruf edin ve yerel olarak veya sunucunuzda çalıştırın. Yapın - getir; npm yükleme.
search.mjsconst 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."); }Run · JavaScriptnode search.mjsPython 3.10+ · search.py olarak tasarruf edin. Sadece standart kütüphaneyi kullanın; pip install. python3 veya py -3 eğer bu sizin Python komutunuzsa.
search.pyimport 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.")Run · Pythonpython -X utf8 search.pySonucu kontrol edin
HTTP başarısını ve status: done'yu doğrulayın. Kaynak başlıklarını, bağlantıları ve parçaları okuyun results[].organic, ve sorumlu usage.credits.
status: done ile boş bir sonuç veya organik bir liste geçerli bir boş sonuçtur.
Örnek yanıt{ "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 } }status- "done", sorgunun başarıyla tamamlandığını onaylar.
results[0].organic[]- Arama sonuçları. Bu sonuçları indekslemeden önce boş değildir.
title / link / snippet- Kaynak adı, URL ve alıntı.
usage.credits- Bu sorgu için kanunen krediler ücretlendi.
Debugging için bir cevap Kaydet
Bir sonraki amaçlanan isteği yakalamak için, yukarıdaki cURL komutlarına bu seçenekleri ekleyin. Başarısız bir istek yeniden denemeye karar vermeden önce dosyaları ihmal edin.
--dump-header response-headers.txt --output result.jsonGiriş ve kredi kontrol
Bu GET, sorgu kredilerini kullanmadan kimlik, denge ve fiyat okumasını talep ediyor. HTTP 200'u bekleyin ve ücretli iş göndermeden önce alanları kontrol edin.
Hesap okur: https://api.flashdata.dev/v2. Data requests: https://data.flashdata.dev/v1. Her ikisi de X-API-Key kullanıyor; JSON POST talepleri de Content-Type: application/json.
(
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
)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
}identity- Amaçlananı doğrulayın accountId, access: "ready", içeren kapsamı "google_search"Ve herhangi bir şey expiresAt. accountType Is is is is Is is Is Is is'dir. "owned" Bir sahibi anahtar veya "temporary" Bir deneme anahtarı için.
balance- availableCredits'u okuyun. Bu hesap için tüm anahtarlar aynı dengeyi kullanır.
pricing- prices[0] için doğru kaynak google_search ve mevcut true. estimatedCredits için requestCount: 1 ile availableCredits. Fiyatlar ve dengeler, teslim almadan önce değişebilir.
Sonraki adımlar
Bir adım başarısız olursa
Terminalinizde basılan cevabı okuyun. JavaScript ve Python raporu HTTP hataları ve Retry-After'yu stderr'ye rapor edin. Her örnek bir kez gönderir; otomatik olarak yeniden denemez.
- Komut eksik veya desteklenmemiş bir seçenek
- Seçilmiş örnekteki gerekli sürümü kontrol edin. PowerShell 7'dan ziyade Windows PowerShell 5.1 veya Bash'yu cURL7.76+ ile kullanın. JavaScript'un 22+'ya ihtiyacı yok; Python'un 3.10+'ya ihtiyacı var. Kayıp runtime'yı resmi indirme sayfasından yükleyin, terminali yeniden açın.
- Eksik anahtar / 401
- Bu süreçte FLASHDATA_API_KEY'u ayarlayın ve tekrar kimlik kontrol edin. Tüm aktif API anahtarı, bir Bearer ön ek olmadan. Eğer sona erseydi veya iptal edildiyse, mevcut bir yetkili credential kullanın; onu sohbete dökmeyin.
- 403
- identity.scopes for google_search ve hazır erişim. Sahibinden eksik izin talep edin; istekteki kaynağı değiştirmek erişim sağlamaz.
- 402
- Tekrar dengeyi okuyun ve mevcut fiyatla karşılaştırın. Sahibi Billing'u inceleyebilir. Bir tükenmiş denemenin sahibinin iddia yoluyla erişimine ihtiyacı vardır; bir yedek deneme oluşturmak iyileşme değildir.
- 400 / 422
- Geri dönüş hata mesajını okuyun. Tam veri hostunu kontrol edin, POST yöntemi, Content-Type ve JSON alan isimlerini kontrol edin. Doğru alıntılar ve sayısal bir params.num kullanın, sonra reddedilen isteği düzeltin.
- 429
- Retry-After'a saygı gösterin; aksi takdirde bir geri dönüş kullanın ve koncurrency azaltır. Hızlı bir şekilde döngüsü yapmayın, sınırı atlamak için yeni anahtarlar oluşturun veya başka bir deneme kayıt edin.
- HTTP 200 başarısız statü veya hatayla
- Vücuttaki hatayı okuyun ve herhangi bir istek veya işi korur ID. Başarılı bir görev olarak parsed JSON vücuduna tedavi etmeyin veya otomatik olarak yeniden ortaya çıkarın.
- Boş sonuçlar
- Durum yapılırsa, doğrulama çalıştı. Boş sonucu tutun veya yeni ücretli bir istek olarak daha geniş bir sorgu deneyin.
- Zaman, bağlantı kaybı, 5xx veya HTML yerine JSON
- Bir POST cevabı kaybedilmiş olsa bile kabul edilebilir. History'u orijinal sorgu için kontrol edin ve geri dönmeden önce IDs'ya geri dön. Free GET checks yeniden kullanılabilir. URL, data.flashdata.dev'u kullanarak onaylayın ve TLS doğrulamasını engellemeyin.