Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails JSON::ParserError异常:757:在';未设置令牌作用域。此请求没有所需的权限;_Ruby On Rails_Ruby_Autodesk Forge - Fatal编程技术网

Ruby on rails JSON::ParserError异常:757:在';未设置令牌作用域。此请求没有所需的权限;

Ruby on rails JSON::ParserError异常:757:在';未设置令牌作用域。此请求没有所需的权限;,ruby-on-rails,ruby,autodesk-forge,Ruby On Rails,Ruby,Autodesk Forge,我正在使用adn_viewer gem()将Autodesk与Ruby on Rails集成。使用以下代码创建bucket时: 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") h

我正在使用adn_viewer gem()将Autodesk与Ruby on Rails集成。使用以下代码创建bucket时:

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

这个示例已经过时,没有维护,去年生产的Ruby包也没有维护。 我们即将发布一个新的包和样本,以匹配去年6月正式发布的API的最新状态。同时,您至少需要添加bucket:create作用域作为此API的文档here:和here:

使用所需的适当范围更改身份验证调用。通常数据:读取数据:写入数据:更新存储桶:读取存储桶:创建存储桶:更新

更改此行: 与:

JSON.parse(corbfu.post({:host=>'developer.api.autodesk.com',:path=>'/authentication/v1/authenticate',:protocol=>“https”},{:client\u id=>key,:client\u secret=>secret,:grant\u type=>'client\u credentials',:scope=>'put your scope=>'put your scopes here}.body)


希望对您有所帮助,

它看起来像您的
http.request(request)。read\u body
不是JSON编码的字符串;它只是一根线。JSON编码的字符串需要解码为数组或哈希才能有效。谢谢您的回答。我会检查并更新你的。你好@cyrille,我能够创建bucket并上传其中的文件。但是,当我试图打开查看器并查看其中的文件时,我在以下文件中遇到了JS错误:它说:viewer3D.min.JS:4 Uncaught InvalidStateError:未能从“XMLHttpRequest”读取“responseText”属性:仅当对象的“responseType”为“”或“text”(was“json”)时,才可以访问该值。p@viewer3D.min.JS:4,它是在打开查看器之前下载文件。你能在这方面提供帮助吗?如果你能把你的代码发布到某个地方供我测试,我很乐意试一试。我的最小查看器示例是post there,其中我将URN和access_标记作为查询字符串中的参数。