/**
|
* 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(() => [])
|
}
|