排序新闻api端点



我的任务是在点击的同时对所有内容和头条文章进行排序。

我正在使用此新闻api:https://newsapi.org/

我目前的终点:

@GET("top-headlines?sources=bbc-news&apiKey=${BuildConfig.API_KEY}")
suspend fun getTopHeadlinesArticles(
@Query("page")  page:Int = 1
) : Response<ArticleListResponse>
@GET("everything?q=tesla&sortBy=publishedAt&apiKey=${BuildConfig.API_KEY}")
suspend fun getAllArticles(
@Query("page") page: Int = 1
) : Response<ArticleListResponse>

sortBy的问题是,它只在所有端点中可用,如果我在头条新闻中使用它,它什么都不做。我试过使用sortBy=publishedAt和-publishedAt。

Json示例:

"status": "ok",
"totalResults": 37,
"articles": [
{
"source": {
"id": "reuters",
"name": "Reuters"
},
"author": null,
"title": "Russia says it resumes participation in Ukraine grain deal - Reuters.com",
"description": "Russia said on Wednesday it would resume its participation in a deal to free up vital grain exports from war-torn Ukraine after suspending it over the weekend in a move that had threatened to exacerbate hunger across the world.",
"url": "https://www.reuters.com/world/europe/grain-ships-sail-ukraine-ports-russian-missiles-knock-out-power-across-country-2022-10-31/",
"urlToImage": "https://www.reuters.com/resizer/0q0d5ZOWPFOkR2Yc_Mbv8TQZrAA=/1200x628/smart/filters:quality(80)/cloudfront-us-east-2.images.arcpublishing.com/reuters/NQYU2CZKHRNKRDPQ76IQYOV2DE.jpg",
"publishedAt": "2022-11-02T10:43:00Z",
"content": "ANKARA/MYKOLAIV, Ukraine, Nov 2 (Reuters) - Russia said on Wednesday it would resume its participation in a deal to free up vital grain exports from war-torn Ukraine after suspending it over the week… [+2828 chars]"

来自新闻api文档:文章按最先发布的最早日期排序。

我想按升序和降序排序。

top-headlines端点的文档列出了所有可能的请求参数,但没有一个参数控制排序。因此,不幸的是,无法更改此端点的排序。您可以尝试向他们提交功能请求,方法是发送电子邮件至support@newsapi.org.

最新更新