使用 Google Custom Search JSON API 查詢客製化搜尋引擎

做法

首頁,在 Programmable Search Engine 建立一個客製化搜尋引擎,將搜尋引擎 ID 複製起來。

Google Cloud 新增一個專案,並且建立憑證,將 API 金鑰複製起來。

最後,啟用 Custom Search API 產品。

發送請求

使用 fetch 發送請求。

1
await (await fetch('https://customsearch.googleapis.com/customsearch/v1?key=your-api-key&cx=your-search-engine-id&lr=lang_zh-TW&q=台灣')).json()

參考資料