简体   繁体   English

使用 API 获取 Chocolatey 包列表

[英]Get list of Chocolatey packages using API

Is there a way to use the OData api on the chocolatey.org site to obtain a list of all packages available in the community repo?有没有办法使用 Chocolatey.org 站点上的 OData api 来获取社区存储库中所有可用包的列表?

What I've tried:我试过的:

I can see using the $metadata service that Packages is exposed:我可以看到使用 $metadata 服务公开 Packages:

https://chocolatey.org/api/v2/ $metadata https://chocolatey.org/api/v2/ $metadata

From this I can use something like this to get the first "page" of XML:从这里我可以使用这样的东西来获取 XML 的第一个“页面”:

http://chocolatey.org/api/v2/Packages() ?$skip=0 http://chocolatey.org/api/v2/Packages() ?$skip=0

The website limits to 40 "entries" by default I think, so the $skip can be altered accordingly.我认为该网站默认限制为 40 个“条目”,因此可以相应地更改 $skip。

(Another way is to use the $skipToken which points to the next "page"). (另一种方法是使用指向下一个“页面”的 $skipToken)。

All versions seem to return in the responses.所有版本似乎都在响应中返回。 It would be irresponsible to write a loop to effectively download the database.编写一个循环来有效下载数据库是不负责任的。 I don't think the site owners would appreciate this.我不认为网站所有者会欣赏这一点。 I'm not planning to do this regularly.我不打算定期这样做。

Reasons for doing this aside, is there a better way to get the package list using only the API, not via the choco CLI?除了这样做的原因之外,是否有更好的方法来仅使用 API 而不是通过 choco CLI 来获取包列表?

Update 1 Getting warmer using filters - clue in the metadata eg.更新 1 使用过滤器变得更温暖 - 例如元数据中的线索。 https://chocolatey.org/api/v2/Packages() ?$filter=IsLatestVersion This now returns latest versions only at least. https://chocolatey.org/api/v2/Packages() ?$filter=IsLatestVersion 现在至少只返回最新版本。

You could use something like Fiddler to inspect the traffic going from the Chocolatey CLI.您可以使用类似Fiddler 的工具来检查来自 Chocolatey CLI 的流量。 Issuing choco search git reveals the following request:发出choco search git显示以下请求:

GET /api/v2/Search()?$filter=IsLatestVersion&$skip=0&$top=30&searchTerm='git'&targetFramework=''&includePrerelease=false HTTP/1.1

Please note that you shouldn't be using their API without contacting them first.请注意,您不应该在没有先联系他们的情况下使用他们的 API。 Even if it's just for personal use.即使它只是供个人使用。 They have no public documentation for their APIs, and so it should be treated as an internal resource.他们的 API 没有公开文档,因此应将其视为内部资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM