kotlin 排序新闻API端点

mlmc2os5  于 2022-11-16  发布在  Kotlin
关注(0)|答案(1)|浏览(142)

我的任务是排序一切和顶部标题文章在同一点击。
我用的是这个新闻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文档:文章按最早发表的日期排序。
我想按升序和降序排序。

f4t66c6m

f4t66c6m1#

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

相关问题