How to reload users with soundcloud on every page?

I am using Javascript SDK inside node.js (Express) app.

User connection works fine, but connection does not persist between page reloads. Is this the default behavior, or should the user stay connected to new requests?

Do I need to use OAuth token authentication, and if so, how can this be done with the JS-SDK? Inside "Permission" -Popup, users are already logged in with soundlcoud. (you just need to press the "connect" button every time)

+2


source to share


2 answers


Yes, that's the way to do it officially. :)

For the Next SoundCloud site, we store the token in localStorage (until the user logs out, of course). In every AJAX API request from the frontend, we put the oauth token in the request header:



jqXHR.setRequestHeader('Authorization', 'OAuth ' + the_oauth_token);

      

+2


source


After realizing that I have shared my answer to those who are not satisfied with the current automatic oauth answers:

Retrieving access_token:

I needed to define the get and set cookie functions and then I use the functions to set and retrieve the function containing the access token. I'm not going to give these functions for brevity, but you can easily find them with a google search. Then I use this line of code to get the SC access token (as soon as the user is authenticated the first time)

SC.accessToken()

      

Setting the token:

So, it's kind of like an elephant in a room, in my opinion, for some reason no one mentioned it. How in **** do you connect w / SC with an access token? Are you setting it as oauth param? Does it pass on every call? Well, after experimenting with putting the parameter in each separate location, I might think I found out that you should do something like this:



            SC.initialize({
              client_id: '[removed for security reasons]',
              client_secret: '[removed for security reasons]',
              redirect_uri: '[removed for security reasons]',
              access_token: getCookie("sc_lm2"),
              scope: 'non-expiring'
            }); 
//Where "sc_lm2" is the name of my cookie

      

Hope it helps! Spent me to figure it out for such a simple thing.

EDIT

Using PHP and Wordpress:

$json = wp_remote_get("http://api.soundcloud.com/users/[user_id]/tracks.json?client_id=[client_id]");
$soundcloudData = json_decode($json['body'],true);

      

(replace functionality with cURL if you are not using Wordpress). @krafty I'm assuming you just change the endpoint from "/ tracks" to "/ users", but I can't say that I've ever really needed to capture anything other than tracks using the Soundcloud API. Hope this helps, although I'm not sure I fully understand what you are trying to accomplish (more precisely, how exactly are you doing it) - are you trying to allow user logins? If you want to fully explain what you are trying to accomplish and the steps you are taking, I would be happy to hack it.

+3


source







All Articles