메인 콘텐츠로 건너뛰기

소개

Google Search는 Ace Data Cloud에서 제공하는 검색 서비스인 Google 검색 API입니다. Ace Data Cloud 통합 API를 통해 JavaScript로 Google Search를 빠르게 통합하여 웹 검색, 이미지 검색, 뉴스 검색, 지도 검색, 동영상 검색 등의 기능을 구현할 수 있습니다.

전제 조건

  • Ace Data Cloud 계정을 보유하고 API 토큰을 발급받았을 것
  • Node.js 18+ 또는 최신 브라우저 환경

기본 사용법

Google Search API의 주요 엔드포인트는 다음과 같습니다:
POST https://api.acedata.cloud/serp/google
전체 JavaScript 코드 예제:
const response = await fetch("https://api.acedata.cloud/serp/google", {
  method: "POST",
  headers: {
    "Authorization": "Bearer YOUR_API_TOKEN",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
  "query": "artificial intelligence latest news",
  "type": "search",
  "number": 10,
  "language": "en",
  "country": "US"
}),
});

const result = await response.json();
console.log(result);
YOUR_API_TOKEN을 Ace Data Cloud 플랫폼에서 발급받은 실제 토큰으로 교체하세요.

응답 처리

응답 상태 코드를 확인하고 오류를 처리하는 것을 권장합니다:
if (response.ok) {
  const result = await response.json();
  console.log("호출 성공:", result);
} else {
  console.error(`호출 실패, 상태 코드: ${response.status}`);
  const error = await response.text();
  console.error(error);
}

Node.js 래퍼 함수

재사용 가능한 함수로 래핑하는 것을 권장합니다:
async function callGoogleSearch(data) {
  const response = await fetch("https://api.acedata.cloud/serp/google", {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${process.env.ACE_API_TOKEN}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify(data),
  });
  if (!response.ok) throw new Error(`API error: ${response.status}`);
  return response.json();
}

오류 처리

일반적인 오류 코드:
상태 코드설명
401인증 실패, API 토큰을 확인하세요
403잔액 부족 또는 접근 권한 없음
429요청 빈도 초과
500서버 내부 오류

다음 단계