自动化 GitHub API 以创建 repos/Gists return 200 OK 而不是 201 Created
Automating GitHub API for creating repos/Gists return 200 OK instead of 201 Created
我使用 Postman 创建一个要点,我在授权选项卡中添加了不记名令牌,但它应该创建一个要点并且 return 201 Created 而不是它 returns 200 OK,它没有创建任何东西
enter image description here
我在请求正文中写了 GitHub 文档中提到的示例来创建 Gist
{
"description": "Hello World Examples",
"public": true,
"files": {
"hello_world.rb": {
"content": "class HelloWorld\n def initialize(name)\n @name = name.capitalize\n end\n def sayHi\n puts \"Hello !\"\n end\nend\n\nhello = HelloWorld.new(\"World\")\nhello.sayHi"
},
"hello_world.py": {
"content": "class HelloWorld:\n\n def __init__(self, name):\n self.name = name.capitalize()\n \n def sayHi(self):\n print \"Hello \" + self.name + \"!\"\n\nhello = HelloWorld(\"world\")\nhello.sayHi()"
},
"hello_world_ruby.txt": {
"content": "Run `ruby hello_world.rb` to print Hello World"
},
"hello_world_python.txt": {
"content": "Run `python hello_world.py` to print Hello World"
}
}
}
https://docs.github.com/en/free-pro-team@latest/rest/reference/gists#create-a-gist
Authentication You can read public gists anonymously, but you must be
signed into GitHub to create gists. To read or write gists on a user's
behalf, you need the gist OAuth scope and a token. For more
information, see "Scopes for OAuth Apps."
您应该经过身份验证,否则您将只有读取权限,这就是为什么您得到的是 200 而不是 201
第二个原因:您使用的是 http 而不是 https
使用开发者设置生成的令牌作为 oauth2 载体:
我使用 Postman 创建一个要点,我在授权选项卡中添加了不记名令牌,但它应该创建一个要点并且 return 201 Created 而不是它 returns 200 OK,它没有创建任何东西 enter image description here
我在请求正文中写了 GitHub 文档中提到的示例来创建 Gist
{
"description": "Hello World Examples",
"public": true,
"files": {
"hello_world.rb": {
"content": "class HelloWorld\n def initialize(name)\n @name = name.capitalize\n end\n def sayHi\n puts \"Hello !\"\n end\nend\n\nhello = HelloWorld.new(\"World\")\nhello.sayHi"
},
"hello_world.py": {
"content": "class HelloWorld:\n\n def __init__(self, name):\n self.name = name.capitalize()\n \n def sayHi(self):\n print \"Hello \" + self.name + \"!\"\n\nhello = HelloWorld(\"world\")\nhello.sayHi()"
},
"hello_world_ruby.txt": {
"content": "Run `ruby hello_world.rb` to print Hello World"
},
"hello_world_python.txt": {
"content": "Run `python hello_world.py` to print Hello World"
}
}
}
https://docs.github.com/en/free-pro-team@latest/rest/reference/gists#create-a-gist
Authentication You can read public gists anonymously, but you must be signed into GitHub to create gists. To read or write gists on a user's behalf, you need the gist OAuth scope and a token. For more information, see "Scopes for OAuth Apps."
您应该经过身份验证,否则您将只有读取权限,这就是为什么您得到的是 200 而不是 201
第二个原因:您使用的是 http 而不是 https
使用开发者设置生成的令牌作为 oauth2 载体: