문서 둘러보기
시작하기
SDK를 설치하고 Node.js에서 검색을 실행합니다. TypeScript 또는 JavaScript를 선택하십시오. 서버에서 API 키를 유지하십시오.
SDK 설치
이 예제는 Node.js 22.18+를 사용하여 TypeScript를 직접 실행합니다. 빈 폴더에서 시작하거나 package.json가 있는 경우 Existing 프로젝트를 선택하십시오.
설치npm init -y npm install --save-exact @flashdata-dev/[email protected]설치npm install --save-exact @flashdata-dev/[email protected]인증현황
Google Search 권한으로 키 생성하거나 권한된 키를 재사용합니다. 아래 숨겨진 프롬프트를 사용하여이 터미널에서 FLASHDATA_API_KEY를 설정; 이미 그것을 공급하는 경우이 작업을 건너.
예를 들어 키가 명시적으로 전달합니다. .env 파일은 이 스크립트에 의해 로드되지 않습니다. 웹 응용 프로그램에 통합 할 때 서버 측 구성의 키를 유지하십시오.
숨겨진 키 프롬프트 · 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# 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검색 실행
선택한 파일을 저장하고 이 프로젝트에서 명령을 실행합니다. 각 실행은 최대 5개의 결과에 대한 한 검색을 제출합니다. 두 파일 모두 Node.js와 직접 실행; 빌드 단계는이 예제에 필요하지 않습니다.
quickstart.mtsimport { FlashData, type GoogleSearchParams } from '@flashdata-dev/sdk'; const apiKey = process.env.FLASHDATA_API_KEY; if (!apiKey) throw new Error('Set FLASHDATA_API_KEY in the server environment.'); const client = new FlashData({ apiKey }); const params: GoogleSearchParams = { num: 5 }; const response = await client.google.search({ query: 'battery recycling research', ...params }); if (response.status !== 'done') throw new Error(JSON.stringify(response)); for (const page of response.results) { for (const hit of page.organic ?? []) console.log(hit.title, hit.link); } console.log('Credits used:', response.usage.credits);실행 · Node.js 22.18+node quickstart.mtsquickstart.mjsimport { FlashData } from '@flashdata-dev/sdk'; const apiKey = process.env.FLASHDATA_API_KEY; if (!apiKey) throw new Error('Set FLASHDATA_API_KEY in the server environment.'); const client = new FlashData({ apiKey }); const response = await client.google.search({ query: 'battery recycling research', num: 5 }); if (response.status !== 'done') throw new Error(JSON.stringify(response)); for (const page of response.results) { for (const hit of page.organic ?? []) console.log(hit.title, hit.link); } console.log('Credits used:', response.usage.credits);실행node quickstart.mjs결과 확인
스크립트는 상태가 완료되고 소스 제목, URLs 및 크레딧을 인쇄합니다. 빈 유기 결과는 유효합니다. 아래 예제 출력은 모양을 설명합니다. 라이브 소스는 다를 수 있습니다.
예 출력Battery recycling research https://example.org/recycling Credits used: 0.02results[].organic[]- Google Search 제목, 링크 및 스니펫. 다른 소스는 자신의 유형의 페이로드가 있습니다.
usage.credits- 이 요청에 대해 청구되는 크레딧; 5 개의 반환된 조회는 하나의 검색 요청입니다.
다른 데이터 소스를 시도
각 탭은 TypeScript와 JavaScript 모두에서 작동합니다. 단계 3에서 파일을 바꾸고 .mts 또는 .mjs 확장을 유지하고 동일한 명령을 실행하십시오. 각 실행은 새로운 요청이며 소스 권한이 표시됩니다.
google_news를 요구합니다. results[].news[]에서 기사 항목을 읽으십시오.
import { FlashData } from '@flashdata-dev/sdk';
const apiKey = process.env.FLASHDATA_API_KEY;
if (!apiKey) throw new Error('Set FLASHDATA_API_KEY first.');
const client = new FlashData({ apiKey });
const response = await client.google.news({
query: 'battery recycling', num: 5,
});
if (response.status !== 'done') throw new Error(JSON.stringify(response));
console.log(response);youtube_metadata를 요구합니다. 제목, 채널, 기간 및 기타 비디오 세부 사항을 반환합니다.
import { FlashData } from '@flashdata-dev/sdk';
const apiKey = process.env.FLASHDATA_API_KEY;
if (!apiKey) throw new Error('Set FLASHDATA_API_KEY first.');
const client = new FlashData({ apiKey });
const response = await client.youtube.metadata({
video_id: 'dQw4w9WgXcQ', include_formats: false,
});
if (response.status !== 'done') throw new Error(JSON.stringify(response));
console.log(response);youtube_transcript를 요구합니다. 기존 영어 자동 트랙을 요청합니다. 텍스트는 results[].fullText에서 트랙을 사용할 수 있습니다.
import { FlashData } from '@flashdata-dev/sdk';
const apiKey = process.env.FLASHDATA_API_KEY;
if (!apiKey) throw new Error('Set FLASHDATA_API_KEY first.');
const client = new FlashData({ apiKey });
const response = await client.youtube.transcript({
video_id: 'dQw4w9WgXcQ', language: 'en', auto: true,
});
if (response.status !== 'done') throw new Error(JSON.stringify(response));
console.log(response);TypeScript 프로젝트
Node는 stripping 유형으로 이 예제를 실행합니다. 요청을 보내지 않고 형식을 확인하려면 TypeScript를 설치하고 --noEmit와 컴파일러를 실행하십시오.:
npm install --save-dev typescript@~5.9.3 @types/node@^22
npx tsc quickstart.mts --module nodenext --target es2022 --strict --noEmitSDK 지원
google / youtube- Typed source helpers를 사용하여 구조화 된 데이터를 검색하고 검색합니다. 서비스에서 1개의 클라이언트를 재사용하십시오.
youtube.download- 배경 작업을 통해 오디오 또는 비디오를 클라우드 스토리지에 전달합니다. youtube_download 권한 및 저장 구성이 필요합니다.
jobs / bulk- IDs를 저장하고 완료된 결과를 검색하십시오. JavaScript의 대기를 기다리십시오; mode: 'async'는 서버 측 배경 일을 제출합니다.
account- 복구 작업 전에 액세스, 균형, 가격, 제한 및 사용 읽으십시오.
respondWith / accept- 패스워드 { respondWith: 'markdown' } 메소드의 두 번째 인수로 Markdown 으로 response.content, 또는 { accept: 'text/plain' } 문자열에 대한. JSON 객체는 기본값입니다.
다음 단계
단계가 실패한 경우
- 패키지 또는 실행 시간 누락
- 노드 --version를 확인하고 이 프로젝트에서 @flashdata-dev/sdk를 설치하십시오. 위에 표시된 .mts 또는 .mjs 확장을 지키십시오.
- 401 / FLASHDATA_API_KEY
- 예를 실행하는 터미널에서 유효한 키를 설정합니다.
- 403
- 이 API 열쇠를 위한 가능하게 하는 Google Search.
- 402
- Billing를 사용 가능한 신용을 확인하거나 소진된 에이전트 체험을 주장합니다.
- 429
- Retry-After를 기다리면 요청 속도를 줄입니다.
- Timeout 또는 서버 오류
- History를 다시 구출하기 전에 확인하십시오. 첫 번째 요청은 이미 실행 될 수 있습니다.