我收到“400 Bad Request”和“你忘了身体变量吗?” 代码:
require "rest-client"
require "json"
# This is the ID that you copied down in the last exercise
your_folder_id = "816582409"
# Add the "body" variable here
body = { "description" => "I made this on Codecademy!"
}
response = RestClient.put(
"https://api.box.com/2.0/folders/#{816582409}",
JSON.generate(body),
:authorization => "Bearer" << "AKGEp7MoDfLAKnMyxTt3nSNtohXW3bt1"
)
JSON.parse(response.body)["description"]
答案 0 :(得分:1)
api通话的网址不应该是https://api.box.com/2.0/folders/816582409
或"https://api.box.com/2.0/folders/#{@your_folder_id}"
?
答案 1 :(得分:0)
你在Bearer和废话之间缺少一个空格。你有类似的东西:
response = RestClient.put(
"https://api.box.com/2.0/folders/#{816582409}",
JSON.generate(body),
:authorization => "Bearer " << "AKGEp7MoDfLAKnMyxTt3nSNtohXW3bt1"
)
答案 2 :(得分:0)
"https://api.box.com/2.0/folders/#{816582409}"
评估为"https://api.box.com/2.0/folders/"
。正如ararog建议的那样,将变量本身放在:#{@your_folder_id}
或普通数字中,而不是#{816582409}