簡體   English   中英

下載與主題匹配的 GitHub 存儲庫列表?

[英]Download GitHub repositories list matching a topic?

有沒有辦法下載與 GitHub 主題匹配的項目列表? 例如,如果我寫:

https://github.com/topics/haskell

在 Web 瀏覽器中,返回包含與 Haskell 相關的 GitHub 項目的頁面。 我閱讀了他們的 GitHub API,但他們似乎沒有實現該功能: https : //developer.github.com/v3/

此外端點https://api.github.com/似乎不包含任何選項。 我從https://api.github.com/topics/haskell 等嘗試中得到的結果是:

{
  "message": "Not Found",
  "documentation_url": "https://developer.github.com/v3"
}

如果要搜索與主題匹配的存儲庫,請使用/search/repositoriestopic屬性:

curl -H "Accept: application/vnd.github.mercy-preview+json" \
    https://api.github.com/search/repositories?q=topic:haskell

你必須提供application/vnd.github.mercy-preview+json當它仍然在開發者預覽中時:

注意:GitHub 上存儲庫的主題屬性目前可供開發人員預覽。 要在返回存儲庫結果的調用中查看主題屬性,您必須在 Accept 標頭中提供自定義媒體類型:

應用程序/vnd.github.mercy-preview+json

主題的正確 GitHub API 端點是: https://api.github.com/search/topics : https://api.github.com/search/topics ,您需要在q查詢參數中提供主題查詢。 這是直接來自API 文檔的示例查詢:

curl -H 'Accept: application/vnd.github.mercy-preview+json' 'https://api.github.com/search/topics?q=ruby+is:featured'

這是一個尋找您的搜索主題“haskell”的示例:

curl -H 'Accept: application/vnd.github.mercy-preview+json' 'https://api.github.com/search/topics?q=haskell'

請參閱: https : //developer.github.com/v3/search/#search-topics

“您可以在所有 GitHub Enterprise 中全局搜索代碼,或在特定存儲庫或組織內搜索代碼。要在所有公共存儲庫中搜索代碼,您必須登錄 GitHub Enterprise 帳戶。”

這個 curl 只會返回標簽或主題 curl -H 'Accept: application/vnd.github.mercy-preview+json' 'https://api.github.com/search/topics?q=haskell'

來源: https : //help.github.com/en/enterprise/2.13/user/articles/searching-code# :~: text=You%20can%20search%20for%20code%20globally%20across%20all%20of%20GitHub ,%22關於%20searching%20on%20GitHub。%22

您可以使用 GraphQL API 來獲取主題中的存儲庫。

試試看: https : //docs.github.com/en/graphql/overview/explorer

query { 
  search(first: 10, type: REPOSITORY, query: "topic:databases") {
    repositoryCount
    nodes {
      ... on Repository {
        nameWithOwner
      }
    }
  }
}
{
  "data": {
    "search": {
      "repositoryCount": 831,
      "nodes": [
        {
          "nameWithOwner": ".../..."
        },
        {
          "nameWithOwner": ".../..."
        },
...

警告:您不能使用 GraphQL api 來獲取主題列表。

主題查詢是有限的。

有用於搜索單個主題的Query.topicRepository.repositoryTopics Topic.relatedTopics存在為“相關主題列表,包括此主題的別名,按最相關的在前排序。返回最多 10 個主題。”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM