0

我收到“400 Bad Request”和“你忘记了 body 变量吗?” 代码:

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"]
4

3 回答 3

1

api 调用的 url 不应该是https://api.box.com/2.0/folders/816582409or "https://api.box.com/2.0/folders/#{@your_folder_id}"?

于 2013-04-18T14:00:26.950 回答
0

"https://api.box.com/2.0/folders/#{816582409}""https://api.box.com/2.0/folders/" 由于字符串插值,计算结果为。正如 ararog 建议的那样,将变量本身放入:#{@your_folder_id}或纯数字,而不是#{816582409}

于 2013-04-18T14:34:55.153 回答
0

您在 Bearer 和废话之间缺少一个空格。你有类似的东西:

response = RestClient.put(
"https://api.box.com/2.0/folders/#{816582409}", 
JSON.generate(body),
:authorization => "Bearer " << "AKGEp7MoDfLAKnMyxTt3nSNtohXW3bt1"
)
于 2013-04-18T13:53:27.813 回答