用關鍵字查詢 Google 新聞報導,回傳結構化 JSON(含標題、連結、來源、發布時間)。認證以 Authorization: Bearer YOUR_API_KEY 標頭帶開發者金鑰(也接受 X-Dev-Key 標頭),或已登入的網頁 session;金鑰不可放在網址查詢參數(會進入伺服器紀錄)。GET 呼叫,參數 q(關鍵字,string)必填;呼叫成功會自動扣點數,查詢失敗或查無結果不扣點。網頁搜尋請見 Google Search API 分頁。
GET https://www.myai168.com/rocna/api/google/newsGoogle 新聞,回傳新聞報導(每筆含 title/link/source/date;連結會盡量還原為原始文章網址)。選填參數:hl 介面語言、gl 地區、ceid(格式 國家:語言,例 TW:zh-Hant)、num 回傳筆數(1~20,預設 10)。
curl "https://www.myai168.com/rocna/api/google/news?q=Taiwan&hl=zh-TW&gl=tw&num=10" \
-H "Authorization: Bearer YOUR_DEV_KEY"
import requests
r = requests.get(
"https://www.myai168.com/rocna/api/google/news",
headers={"Authorization": "Bearer YOUR_DEV_KEY"},
params={"q": "Taiwan", "hl": "zh-TW", "gl": "tw", "num": "10"},
)
print(r.json())
成功回 HTTP 200 JSON 物件:帶回生效的查詢參數(q/hl/gl 等)、count(筆數)、results(結果陣列)、cost(本次扣點)與 credits(扣後餘額);回應標頭另帶 X-Cost-Points(本次扣點)與 X-Credits-Remaining(扣後餘額)。results 每筆含 title/link/source/date(連結會盡量還原為原始文章網址)。
{
"q": "Taiwan",
"count": 10,
"results": [
{"title": "...", "link": "https://...", "source": "...", "date": "..."}
],
"cost": 66,
"credits": 12345
}
| HTTP 狀態 | 意義 |
|---|---|
401 | 金鑰缺漏或無效(同 IP 連續失敗會被暫時封鎖)。 |
402 | 點數不足(請先儲值)。 |
400 | 缺 q 參數或參數格式錯誤。 |
502 | 搜尋服務暫時失敗——一律不扣點。 |