def upload_to_soundcloud
p params
@client = Soundcloud.new(:access_token => current_user.access_token)
p @client
track = @client.post('/tracks', :track => {
:title => 'songName',
:asset_data => params['songFile']
})
p track
end
p个参数:
Parameters: {"songFile"=>#<ActionDispatch::Http::UploadedFile:0x007fd4a7ba64d0 @original_filename="blob", @content_type="audio/wav", @headers="Content-Disposition: form-data; name=\"songFile\"; filename=\"blob\"\r\nContent-Type: audio/wav\r\n", @tempfile=#<Tempfile:/var/folders/fy/0hq5vn9938v5r777d_3ty0lh0000gn/T/RackMultipart20140821-83090-1c8gkb2>>}
p @客户:
#<SoundCloud::Client:0x007fd4aa05bf00 @options={:site=>"soundcloud.com", :on_exchange_token=>#<Proc:0x007fd4a3e6a4b8@/Users/darrendahl/.rvm/gems/ruby-2.0.0-p481/gems/soundcloud-0.3.2/lib/soundcloud/client.rb:11 (lambda)>, :access_token=>"--- !ruby/hash:SoundCloud::HashResponseWrapper\naccess_token:{access_token}\nscope: non-expiring\n"}>
我从发布跟踪请求中得到此错误:
SoundCloud::ResponseError - HTTP status: 401 Unauthorized:
soundcloud (0.3.2) lib/soundcloud/client.rb:152:in `handle_response'
soundcloud (0.3.2) lib/soundcloud/client.rb:32:in `post'
app/controllers/songs_controller.rb:22:in `upload_to_soundcloud'
actionpack (3.2.13) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.13) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.13) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.13) lib/active_support/callbacks.rb:414:in `_run__629916066604458588__process_action__2865853734394445716__callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.13) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.13) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.13) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.13) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.13) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.13) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.13) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.13) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.13) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.13) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:36:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:612:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.5) lib/rack/etag.rb:23:in `call'
rack (1.4.5) lib/rack/conditionalget.rb:35:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.13) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `_run__405240541142666585__call__4563851468004131522__callbacks'
这是在我成功登录并将soundcloud访问令牌对象存储在数据库中之后。 current_user.access_token部分返回访问令牌。
还有其他人有这个问题吗? 我不确定这是否与oauth和身份验证有关,或者是否从从asset_data上传的对象的类型引发了错误。 该文件非常小,因此不应该是因为文件大小。 是否只有某些类型的对象可以上传? 我尝试在ActionDispatch对象中使用临时文件,但遇到了相同的错误。
我能够使用api登录到soundcloud,并且我获取用户信息的get请求有效,但事实并非如此。 谢谢!
据我通过Golang 401错误读取Soundcloud API Auth的权利,您在成功登录后获得了访问令牌,该令牌用于进一步的调用(例如您的帖子请求),也许您可以尝试?