【发布时间】:2019-06-24 16:30:18
【问题描述】:
我正在尝试使用 v3 api 创建一个 github 存储库,但我总是收到 Not Found 错误。我只想用curl而不用oauth来做。这就是我正在尝试的:
curl -u myusername https://api.github.com/users/repos -d '{"name": "reponame"}'
我错过了什么?
【问题讨论】:
标签: github-api
我正在尝试使用 v3 api 创建一个 github 存储库,但我总是收到 Not Found 错误。我只想用curl而不用oauth来做。这就是我正在尝试的:
curl -u myusername https://api.github.com/users/repos -d '{"name": "reponame"}'
我错过了什么?
【问题讨论】:
标签: github-api
如果没有访问令牌,您将无法做到这一点。 另外,请随时查看我的 GitHub 开源项目Git-Captain。
我创建了一个带有 Node.js 后端和 HTML/JS 前端的 Web 应用程序,您可以将其设置为让 API 为您执行许多此类调用。它有一个 Windows 服务器的分步操作,我将很快添加一个 Linux 分步操作。
只需对项目稍作调整,即可在源中添加一个新端点来为您执行此操作。
回答你的问题,
GitHub API 文档准确解释了如何执行您的请求 on this link。
举个例子:
按照您在 CURL 中的要求,显然将令牌“5199...”替换为您自己的:
curl -i -H "Authorization: token 5199831f4dd3b79e7c5b7e0ebe75d67aa66e79d4" \
-d '{ \
"name": "blog", \
"auto_init": true, \
"private": true, \
"gitignore_template": "nanoc" \
}' \
https://api.github.com/user/repos
或
不在 CURL 中,根据 StackOverflow question 您可以执行以下操作:
https://api.github.com/orgs/<organisation_name>/repos?access_token=<generated token>
or
https://api.github.com/users/<username>/repos?access_token=<generated token>
在正文中,将其作为有效负载传递:
{
<br/>"name": "<Repo Name>",<br/>
"description": "<Whateveryour description is>",<br/>
"homepage": "https://github.com",<br/>
"private": false,<br/>
}
您可以通过转到Settings->Developer Settings-> Personal Access Tokens->Generate new token获取“GitHub中的个人访问令牌”
或执行以下所有操作
curl -u ' USER-NAME-HERE' https://api.github.com/user/repos -d '{"name": "REPO-NAME-HERE"}',它将提示您输入用户密码,更新*
因此,由于某种原因,CURL 根本不起作用,但 Git-Hub API 端点 https://api.github.com/user/repos 确实有效。使用POSTMAN,我能够创建一个新的POST,其URL 为https://api.github.com/user/repos,BODY 设置为:
{
"name": "Hello-World",
"description": "This is your first repository",
"homepage": "https://github.com",
"private": false,
"has_issues": true,
"has_projects": true,
"has_wiki": true
}
然后我转到邮递员的“授权”部分,在“类型”下选择“基本身份验证”输入我的用户名和密码。 点击更新请求,然后发送,我的 repo 就创建好了!
【讨论】: