我的任務是在一次點擊中對所有內容和頭條新聞進行排序。
我正在使用這個新聞 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]"
來自 news api 檔案:文章按最早發表的日期排序。
我想對它進行升序和降序排序。
uj5u.com熱心網友回復:
top-headlines端點的檔案列出了所有可能的請求引數,它們都不能控制排序。因此,不幸的是,無法更改此端點的排序。您可以嘗試通過向 [email protected] 發送電子郵件來向他們提交功能請求。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/526374.html
標籤:科特林排序分页改造
