I am new to using APIs of Websites. But since a long time I wanted to learn this and today started with the simple example of how to access information from soundcloud. Here is the code of the simple example from their website
require rubygems
gem soundcloud-ruby-api-wrapper
require soundcloud
gem oauth
require oauth
# Create a Soundcloud OAuth consumer token object
sc_consumer = Soundcloud.consumer( YOUR_APPLICATION_CONSUMER_TOKEN , YOUR_APPLICATION_CONSUMER_SECRET )
# Create an OAuth access token object
access_token = OAuth::AccessToken.new(sc_consumer, YOUR_OAUTH_ACCESS_TOKEN , YOUR_OAUTH_ACCESS_SECRET )
# Create an authenticated Soundcloud client, based on the access token
sc_client = Soundcloud.register({:access_token => access_token})
# Get the logged in user
my_user = sc_client.User.find_me
# Display his full name
p "Hello, my name is #{my_user.full_name}"
I know what to set as:
- YOUR_APPLICATION_CONSUMER_TOKEN
- YOUR_APPLICATION_CONSUMER_SECRET
as this was given when registering a application on soundcloud.
I set the YOUR_OAUTH_ACCESS_TOKEN to http://api.soundcloud.com/oauth/access_token which was also written on the soundcloud site, but I have no idea where to get the
_YOUR_OAUTH_ACCESS_SECRET_ from.
Is this access secret also a random string that I get from somewhere, do I have to generate it by myself.
EDIT As suggested in the answer of the Elite Gentlemen I also tried the Soundcloud example on authentication. I post here the piece of code which already leads to the error:
require rubygems
gem soundcloud-ruby-api-wrapper
require soundcloud
# oAuth setup code:
# Enter your consumer key and consumer secret values here:
@consumer_application = {:key => QrhxUWqgIswl8a9ESYw , :secret => tqsUGUD3PscK17G2KCQ4lRzilA2K5L5q2BFjArJzmjc }
# Enter the path to your audio file here.
path_to_audio_file = "your/absolute/path/to/audio_file.ext"
# Set up an oAuth consumer.
@consumer = OAuth::Consumer.new @consumer_application[:key], @consumer_application[:secret],
{
:site => http://api.sandbox-soundcloud.com ,
:request_token_path => /oauth/request_token ,
:access_token_path => /oauth/access_token ,
:authorize_path => /oauth/authorize
}
# Obtain an oAuth request token
puts "Get request token"
request_token = @consumer.get_request_token
The error message I receive then is:
OAuth::Unauthorized: 401 Unauthorized
method token_request in consumer.rb at line 217 method get_request_token in consumer.rb at line 139 at top level in test1.rb at line 25
How can this simple example fail?