我使用adn_viewer gem(https://github.com/GetSomeRest/adn_viewer)將Autodesk與Ruby on Rails集成。JSON :: ParserError異常:757:未設置令牌範圍的意外令牌。此請求不具備所需的權限。'
Adn_Viewer.create_bucket(token, name, policy)
在adn_viewer.rb的功能定義如下:在使用下面的代碼創建桶
def self.create_bucket(token, name, policy)
url = URI("https://developer.api.autodesk.com/oss/v1/buckets")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["content-type"] = 'application/json'
request["authorization"] = 'Bearer ' + token
request.body = "{\"bucketKey\":\"" + name + "\",\"policy\":\"" + policy + "\"}"
JSON.parse(http.request(request).read_body)
end
我正的錯誤是:
JSON::ParserError Exception: 757: unexpected token at 'Token scope not set. This request does not have the required privilege.'
它看起來像你的'HTTP .request(request).read_body'不是JSON編碼的字符串;它只是一個字符串。一個JSON編碼的字符串需要解碼爲數組或散列纔有效。 –