我有API密钥,API密码。我正在向API发送一个帖子URL,但它会引发401错误。如何在我的帖子请求中使用(OAUTH)?
@api_key = "ssss"
@api_secret = "sss"
consumer = OAuth::Consumer.new(@api_key, @api_secret)
@auth = OAuth::AccessToken.new(consumer)
def make_request(endpoint,method = "GET",params)
base_url = 'https://api.web3.com/v1/'
if method == "GET"
request_data = CGI.escape(params)
encoded_url = base_url + endpoint + '?q=' + request_data
response = @auth.get(encoded_url)
puts @auth
JSON.parse response.body
else
url = base_url + endpoint
response = RestClient.post(url,@apikey,params)
@auth.response
puts response.code
JSON.parse response.body
end
end
registrationData = {
"webhook_uri" => "http://mydo.com/webhooks-callback-url"
}
puts make_request("webhooks","GET")
puts make_request("webhooks","POST",registrationData)
这是我发送GET和POST请求的代码