/ me / followings / {id}导致401 Unauthorized错误

时间:2013-10-21 05:14:13

标签: ruby soundcloud

我正在使用Ruby的官方SoundCloud API包装器(来自https://github.com/soundcloud/soundcloud-rubysoundcloud)来访问SoundCloud API。 Oauth正在使用并正确设置。我可以访问/me/activities和其他/me/...资源。成功上传声音,查询曲目,评论等。

但是,当我尝试访问特定的关注者(通过id)时,通过以下API调用,我收到401 Unauthorized错误:

api_response = @soundcloud.get("/me/followings/#{params[:id]}")

查询以下列表的工作正常:

api_response = @soundcloud.get("/me/followings")

有关为何会发生这种情况的任何见解?我假设soundcloud gem将oauth_token / client_id适当地附加到API调用,就像它对其他资源一样。

加成

https://github.com/soundcloud/soundcloud-ruby的克隆中,可以使用此RSpec测试重现此内容:

require 'helper'

RSpec.configure do |config|
  WebMock.allow_net_connect!
end

describe SoundCloud do
  context 'initialized with access_token' do
    subject {
      SoundCloud.new(:access_token => ENV['ACCESS_TOKEN'],
                     :client_id => ENV['CLIENT_ID'],
                     :client_secret => ENV['CLIENT_SECRET'])}

    describe "#get /me" do
      it "returns authenticated user details" do
        resp = subject.send(:get, '/me')
        # pp resp.inspect
        expect(resp.kind).to eq('user')
      end
    end
    describe "#get /me/followings" do
      it "returns authenticated user followings" do
        resp = subject.send(:get, '/me/followings')
        # pp resp.inspect
        expect(resp).to be_an Array
        expect(resp[0].kind).to eq('user')
      end
    end
    describe "#get /me/followings/#{ENV['TEST_ID']}" do
      it "returns authenticated user following for id #{ENV['TEST_ID']}" do
        resp = subject.send(:get, "/me/followings/#{ENV['TEST_ID']}")
        # pp resp.inspect
        expect(resp.kind).to eq('user')
      end
    end
  end
end

使用以下脚本运行测试:

#!/bin/bash

export CLIENT_ID='Your Client ID'
export CLIENT_SECRET='Your Client Secret'
export ACCESS_TOKEN='Your Access Token'
export TEST_ID='Id of someone you follow'

echo CLIENT_ID: $CLIENT_ID
echo CLIENT_SECRET: $CLIENT_SECRET
echo ACCESS_TOKEN: $ACCESS_TOKEN
echo TEST_ID: $TEST_ID

echo '------'

ruby -S rspec spec/followings_spec.rb

测试运行后,最后一次测试“#get / me / followings /#{ENV ['TEST_ID']}”会失败,不应该 - 除非我的期望是错误的。

0 个答案:

没有答案