简体   繁体   中英

GitHub API: Get Pinned Repositories

I was looking in the documentation but I couldn't find how to do this. As the title says: How to get a user's pinned repositories using the GitHub API ?

The pinned repositories data is not available on GitHub v3 API. But you can use GitHub's v4 GraphQL API to get the same with the GraphQL query below:

{
  user(login: "GabrielBB") {
    pinnedItems(first: 6, types: REPOSITORY) {
      nodes {
        ... on Repository {
          name
        }
      }
    }
  }
}

The curl request for the above query:

curl -L -X POST 'https://api.github.com/graphql' \
-H 'Authorization: bearer <token>' \
--data-raw '{"query":"{\n  user(login: \"GabrielBB\") {\n pinnedItems(first: 6, types: REPOSITORY) {\n nodes {\n ... on Repository {\n name\n }\n }\n }\n }\n}"
'

The response for the above request:

{
    "data": {
        "user": {
            "pinnedItems": {
                "nodes": [
                    {
                        "name": "xtate"
                    },
                    {
                        "name": "vscode-lombok"
                    },
                    {
                        "name": "react-use-session"
                    },
                    {
                        "name": "Android-CutOut"
                    },
                    {
                        "name": "xvfb-action"
                    },
                    {
                        "name": "Vehicles-API"
                    }
                ]
            }
        }
    }
}

Note : You need to generate a token to access the GraphQL API, which you can generate by following the steps given here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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