Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Soundcloud Authentication and API

Tags:

api

soundcloud

I am new to soundcloud. I have done my research but the soundcloud documentation is lacking severely.

I am trying to understand the API. If anyone can help answer the following questions it would be helpful.

  1. Can I access my tracks through the JavaScript API and retrieve JUST the titles of the tracks?

  2. Where do I get my "User ID" from?

  3. I have created an app. Is the Redirect URI mandatory?

  4. I have tried to use the following https://api.soundcloud.com/tracks?client_id=MY_CLIENT_ID. I get some other members information. And yes I replaced MY_CLIENT_ID with the client_id from my new app.

  5. I have tried to use https://api.soundcloud.com/oauth2/token?client_id=xxx&client_secret=xxx&grant_type=password&username=xxx&password=xxx (with my app client_id, client_secret, username & password and I get a 404...not sure why.

Any response to put me in the right direction would be great. Thanks!

like image 753
user2452555 Avatar asked Oct 21 '22 08:10

user2452555


2 Answers

Can I access my tracks through the JavaScript API and retrieve JUST the titles of the tracks?

No, there's no way of retrieving only the titles, you'll get the whole sound representation in JSON or XML depending on the format parameter sent in request.

Where do I get my "User ID" from?

You could use /resolve endpoint to retrieve an ID from the permalink of the user, yours or any other or, if you authorised the user, you could hit /me endpoint to get the representation of the authorised user.

I have created an app. Is the Redirect URI mandatory?

Yes

I have tried to use the following https://api.soundcloud.com/tracks?client_id=MY_CLIENT_ID. I get some other members information. And yes I replaced MY_CLIENT_ID with the client_id from my new app.

client_id is an id for your application, which is the “client” of SoundCloud API (which is the “server” in this case), your user is something else. If you are talking about “authorised” user when referring to “my client id”, then you could query /me/tracks for the tracks that belong to that user.

I have tried to use https://api.soundcloud.com/oauth2/token?client_id=xxx&client_secret=xxx&grant_type=password&username=xxx&password=xxx (with my app client_id, client_secret, username & password and I get a 404...not sure why.

Please follow the documentation for oauth2 endpoint – the request should be POST and not GET and you need to submit code parameter, value for which you'd get from the code that would run on your Redirect URI – after user successfully signs in that URL will be requested with code as GET parameter, so you can use it.

like image 136
Misha Reyzlin Avatar answered Nov 03 '22 22:11

Misha Reyzlin


Addition to @gryzzly answer. You can access API without token, but you will get it only to your account.

As you can see here, there is an option for username/password authorization, and here you can see example, how to do it using SDK.

When you do your POST request, do all your parameters in the body of the post request:

wget --post-data="client_id=ID&client_secret=SECRET&grant_type=password&username=USERNAME&password=PASSWORD" https://api.soundcloud.com/oauth2/token

Here is the PHP request example:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.soundcloud.com/oauth2/token");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "client_id=ID&client_secret=SECRET&grant_type=password&username=USERNAME&password=PASSWORD");
$result = curl_exec($ch);
curl_close($ch);
like image 36
dikirill Avatar answered Nov 03 '22 22:11

dikirill