我是红宝石编程的新手。我试图在ruby代码下面编写代码,以在Github要点中创建注释。
uri = URI.parse("https://api.github.com/gists/xxxxxxxxxxx/comments")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = (uri.scheme == 'https')
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(uri.request_uri)
request.body = {
"body" => "Chef run failed "
}.to_json
response = http.request(request)
response2 = JSON.parse(response.body)
puts response2
但是我执行下面的脚本然后我总是得到 {"message"=>"Not Found", "documentation_url"=>"https://developer.github.com/v3"}
不知道我在做什么错。感谢帮助。
确保首先通过身份验证。来自有关身份验证的Github API文档:
有三种通过GitHub API v3进行身份验证的方法。在某些地方,需要身份验证的请求将返回404 Not Found,而不是403 Forbidden。这是为了防止私有存储库意外泄露给未经授权的用户。
您可以通过创建OAuth2令牌并将其设置为HTTP标头来完成此操作:
request['Authorization'] = 'token YOUR_OAUTH_TOKEN'
您还可以将OAuth2令牌作为POST参数传递:
uri.query = URI.encode_www_form(access_token: 'YOUR_OAUTH_TOKEN')
# Encoding really isn't necessary though for this though, so this should suffice
uri.query = 'access_token=YOUR_OAUTH_TOKEN'
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句