想用 Product Hunt 的 API 抓一下数据,于是
task :fetch_product_hunt => :environment do
query = "http://api.producthunt.com/v1/posts"
access_token = `My API Key`
response = HTTParty.get(query,
:headers => {'Accept' => 'application/json',
'Content-Type' => 'application/json',
'Authorization' => access_token,
'Host' => 'api.producthunt.com'}).body
decode_response = ActiveSupport::JSON.decode(response)
puts decode_response
end
之前都是直接Get
,好像也不用写 Header 之类,不知道这样写对不对
返回的是{"status"=>"404", "error"=>"Not Found"}
文档在这里https://api.producthunt.com/v1/docs/posts/posts_index_get_the_posts_of_today
比较无语不知道是哪里搞错了....