2016-08-06 31 views
-1

我使用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.' 
+1

它看起來像你的'HTTP .request(request).read_body'不是JSON編碼的字符串;它只是一個字符串。一個JSON編碼的字符串需要解碼爲數組或散列纔有效。 –

回答

0

此示例已經過時,沒有維護,也沒有去年生產的Ruby包。 我們即將發佈一個新的包和樣本,以匹配去年6月正式發佈的API的最新狀態。同時,您至少需要添加存儲桶:爲此API創建作爲文檔的範圍:https://developer.autodesk.com/en/docs/oauth/v2/overview/scopes/和此處:https://developer.autodesk.com/en/docs/data/v2/reference/http/buckets-POST/

使用您需要的適當範圍更改認證呼叫。通常數據:讀取數據:寫入數據的更新鬥:讀鬥:創建鬥:更新

改變這一行:https://github.com/GetSomeRest/adn_viewer/blob/master/lib/adn_viewer.rb#L9 有: JSON.parse(CurbFu.post({:host => 'developer.api.autodesk.com', :path => '/authentication/v1/authenticate', :protocol => "https"}, { :client_id => key, :client_secret => secret, :grant_type => 'client_credentials', :scope=> 'put your scopes here' }).body)

希望幫助,

+0

感謝您的回答。將檢查並更新您。 –

+0

你好@cyrille, 我能夠創建存儲桶並上傳文件。但是當我試圖打開查看器並查看其中的文件時,我收到以下文件中的JS錯誤: https://developer.api.autodesk.com/viewingservice/v1/viewers/viewer3D.min.js 它說: viewer3D.min.js:4 Uncaught InvalidStateError:無法從'XMLHttpRequest'中讀取'responseText'屬性:只有對象的'responseType'是''或'text'(是'json')。p @ viewer3D.min.js:4 另外,它在打開查看器之前下載文件。你能幫助這方面嗎? –

+0

如果你可以將你的代碼發佈到某個地方供我測試,我會很樂意給它一個鏡頭。我最小的查看器示例是在那裏發佈的,在這裏我將URN和access_token作爲查詢字符串中的參數。 https://github.com/cyrillef/models.autodesk.io/blob/master/www/view.html – cyrille