-1

我正在使用 adn_viewer gem ( https://github.com/GetSomeRest/adn_viewer ) 将 Autodesk 与 Ruby on Rails 集成。使用以下代码创建存储桶时:

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.'
4

1 回答 1

0

此示例已过时且未维护,去年生成的 Ruby 包也已过时。我们即将发布一个新的包和示例,以匹配去年 6 月正式发布的 API 的最新状态。与此同时,您需要至少添加 bucket:create scope for this API as document here: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)

希望有帮助,

于 2016-08-07T02:51:20.503 回答