Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
355 views
in Technique[技术] by (71.8m points)

ios - Github使用分页搜索Api?(Github Search Api with Pagination?)

I want to use the Github search API Restfully in my iOS application to query public repositories based on 'language' (programming language) as the primary parameter for the search.

(我想在我的iOS应用程序中彻底使用Github搜索API,以基于“语言”(编程语言)作为搜索的主要参数来查询公共存储库。)

From the API documentation i can understand that the following api gives me what i need.

(从API文档中,我可以理解以下api满足了我的需求。)

https://api.github.com/search/repositories?q=tetris+language:assembly&sort=stars&order=desc

(https://api.github.com/search/repositories?q=tetris+language:assembly&sort=stars&order=desc)

Although, this returns 370 such repositories for the particular language.

(虽然,这会返回370特定语言的此类存储库。)

I want to implement pagination in the iOS app so that i can fetch around 10-30 entires at a time only.

(我想在iOS应用中实现分页,这样我一次只能获取10到30个整体。)

I have seen that github provides pagination for some of their Api's.

(我已经看到github为他们的某些Api提供了分页。)

However when i try the following api's with the 'page' and 'per_page' included in the parameter i still get the same results, not limited to the page or the per_page i want.

(但是,当我尝试在参数中包含“页面”和“ per_page”的以下api时,我仍然会得到相同的结果,而不仅限于我想要的页面或per_page。)

https://api.github.com/search/repositories?q=tetris+language:assembly&sort=stars&order=desc&page=1&per_page=10

(https://api.github.com/search/repositories?q=tetris+language:assembly&sort=stars&order=desc&page=1&per_page=10)

Does the github api provide pagination for this search api?

(github API是否为此搜索API提供分页?)

If so what am i missing?

(如果是这样,我想念什么?)

How do i go about using it?

(我该如何使用它?)

  ask by Sagar translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The total_count is the total number of repositories, not the number of itens that are in the JSON.

(total_count是存储库的总数,而不是JSON中的itens数。)

The pagination is working as expected, try this and see the result, the number of itens in each request is 10 (as you set in the last parameter "per_page)

(分页工作正常,尝试此操作并查看结果,每个请求中的itens数量为10(如您在最后一个参数“ per_page中设置的一样”))

Do a crtl+f by full_name , it will be easier to see the number of itens per request

(通过full_name执行crtl+f ,可以更轻松地查看每个请求的itens数量)

Check the result of this 2 requests.

(检查这2个请求的结果。)

https://api.github.com/search/repositories?q=tetris+language:assembly&sort=stars&order=desc&page=1&per_page=10

(https://api.github.com/search/repositories?q=tetris+language:assembly&sort=stars&order=desc&page=1&per_page=10)

https://api.github.com/search/repositories?q=tetris+language:assembly&sort=stars&order=desc&page=2&per_page=10

(https://api.github.com/search/repositories?q=tetris+language:assembly&sort=stars&order=desc&page=2&per_page=10)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...