2013-04-18 184 views
0

我收到「400錯誤請求」和「你忘記了身體變量?」 代碼:這個ruby代碼有什麼問題?

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

你缺少承載和無意義之間的空間。你有這樣的事情:

response = RestClient.put(
"https://api.box.com/2.0/folders/#{816582409}", 
JSON.generate(body), 
:authorization => "Bearer " << "AKGEp7MoDfLAKnMyxTt3nSNtohXW3bt1" 
) 
1

API調用的網址不應爲https://api.box.com/2.0/folders/816582409"https://api.box.com/2.0/folders/#{@your_folder_id}"

0

"https://api.box.com/2.0/folders/#{816582409}"由於字符串插值而估計爲"https://api.box.com/2.0/folders/"。如ararog所示,將變量本身放置在:#{@your_folder_id}或純數中,而不是#{816582409}