javascript - How to use Soundcloud API (authentication) with Angular.js -
i can use public soundcloud api, struggling callback.html login dialog.
at soundcloud app has following callback redirect uri callback.html: http://localhost:8080/#/callback
on route angular app defines controller desired callback template:
<!doctype html> <html lang="en"> <head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>connect soundcloud</title> </head> <body onload="window.opener.settimeout(window.opener.sc.connectcallback, 1)"> <b style="width: 100%; text-align: center;">this popup should automatically close in few seconds</b> </body> </html>
in root controller defined:
sc.initialize({ client_id: "####", redirect_uri: "http://localhost:8080/#/callback", });
thats why public api works me @ controller:
sc.get('/resolve', { url: 'https://soundcloud.com/someuser' }, function(user) { console.log(user); });
but in same controller following returns 401:
sc.get('/me', function(me) { console.log(me); });
sure, because there no dialog popping login!
so did wrong setting callback.html?
my assumptions:
is it, because there /#/ in url? tried
<base href="/">
,$locationprovider.html5mode(true);
didn't change anything.is it, because should serve callback.html not in spa environment. more independent static page?
is there wrong mapping callback.html?
i using webpack build tool. there wrong that?
do have set else redirect uri @ soundcloud app?
i hope can me that!
my website angularjs+soundcloud too, sure, dont see sc.connect function in code, somewhere else?
my function in controller:
this.connect= function(){ sc.connect(function(response){ sc.get("/me", function(response){ // console.log(response); var data={}; data.token = sc.accesstoken(); data.id = response.id; $rootscope.user.sc_id=data.id; $rootscope.user.sc_token=data.token; soundcloud.savetoken(data); soundcloud.generateauthstring(); //other things }); }); }
Comments
Post a Comment