Github API文档提供了筛选主题的指示,搜索存储库。 有没有一种方法可以使用API从特定仓库获取主题?
{
repository(owner: "twbs", name: "bootstrap") {
repositoryTopics(first: 10) {
edges {
node {
topic {
name
}
}
}
}
}
}
这将返回前10个主题及其名称,如下所示。
响应:
{
"data": {
"repository": {
"repositoryTopics": {
"edges": [
{
"node": {
"topic": {
"name": "css"
}
}
},
{
"node": {
"topic": {
"name": "bootstrap"
}
}
},
{
"node": {
"topic": {
"name": "javascript"
}
}
},
{
"node": {
"topic": {
"name": "html"
}
}
}
]
}
}
}
}
curl -H "Accept: application/vnd.github.mercy-preview+json" https://api.github.com/repos/twbs/bootstrap/topics
{
"names": [
"css",
"bootstrap",
"javascript",
"html",
"jekyll-site",
"scss",
"css-framework",
"sass"
]
}
Accept: application/vnd.github.mercy-preview+json
。GET
请求中添加特定的标题:"Accept":"application/vnd.github.mercy-preview+json"
希望能对您有所帮助!我添加了带有Accept Headers的fetch请求:
fetch("https://api.github.com/users/lucksp/repos",
{
method: "GET",
headers: {
Accept: "application/vnd.github.mercy-preview+json"
}
})
我曾经遇到类似的问题,所以我制作了一个Node模块,只需要一行代码即可完成:
var github_topics = require('github-topics');
var topics = github_topics.gettopics('url_of_repo');
例如
var topics = github_topics.gettopics('https://github.com/Aniket965/blog');