1
jhzh
2026-05-22 ef52095f5e9f0a9fe2da779bb1573947d77d75b6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**
 * NewsAPI.org 头条新闻(直接请求 newsapi.org 完整地址)
 */
const NEWS_API_KEY = 'f39cfa8922534af295491f38f664ea3d'
 
export function fetchNewsHeadlines(params = {}) {
  const country = params.country || 'us'
  const category = params.category || 'business'
  const url = `https://newsapi.org/v2/top-headlines?country=${country}&category=${category}&apiKey=${NEWS_API_KEY}`
  return fetch(url)
    .then((res) => res.json())
    .then((data) => {
      if (data.status === 'ok' && Array.isArray(data.articles)) {
        return data.articles
      }
      return []
    })
    .catch(() => [])
}