Struck at authentication.

564 views
Skip to first unread message

Dilip Reddy

unread,
Mar 26, 2012, 10:11:35 PM3/26/12
to SoundCloudAPI
I've been trying to develop soundcloud api using python on 'Bottle'
framework in Eclipse 'IDE' (mac os). My goal for now is to upload a
track to my account using this api. I've struck at authentication. I'm
able to get 'code' in eclipse IDE. However after authorization, url
can't get redirected to redirect_uri. So far my code is
------------------------------------------------------------------

from bottle import route, run, redirect
import soundcloud

@route('/soundcloud/connected')
def soundcloudapp():
client = soundcloud.Client(
client_id='MY CLIENT ID',
client_secret='MY CLIENT SECRET',
redirect_uri="http://localhost:3000/soundcloud/connected")
client.authorize_url='https://soundcloud.com/connect?
redirect_uri=http://localhost:3000/soundcloud/
connected&response_type=code&client_id=MY CLIENT ID'
return redirect (client.authorize_url)



run(host='localhost', port=3000, debug=True)


-------------------------------------------
after entering "http://localhost:3000/soundcloud/connected/" in my
browser I'm able to authorize to soundcloud. After selecting 'connect'
It's not getting redirected to my localhost. Instead it's redirecting
back to same url which is
"https://soundcloud.com/connect?redirect_uri=http://localhost:3000/
soundcloud/connected&response_type=code&client_id=MY CLIENT ID"

However I'm able to extract code in my eclipse ide.
I'm not an experienced programmer. I guess the problem is with my
wrong usage of bottle framework. Can you suggest me what exactly I
need to do to upload a track to my soundcloud account. Or can you
suggest me other web frameworks with proper commands? Also can you
specify how to get access tokens using my code?

Regards
Dilip Reddy
House Music Producer/DJ
http://www.dilipreddy.com/

Paul Osman

unread,
Mar 27, 2012, 12:41:12 PM3/27/12
to soundc...@googlegroups.com
Hi Dilip,

Looks like you're assigning to client.authorize_url. This isn't correct. After creating the Client instance, 'authorize_url' is a method you can use to get the URL you want to redirect your user to. Here's a corrected snippet:

@route('/soundcloud/connected')
def soundcloudapp():
    client = soundcloud.Client(client_id='MY CLIENT ID', client_secret='MY CLIENT SECRET', redirect_uri='http://localhost:3000/soundcloud/connected')
    return redirect(client.authorize_url())

That should at least get you started. Hope that helps. 

Cheers,
-- 
Paul Osman
Developer Evangelist


SoundCloud HQ USA
San Francisco CA, 94110
--
You received this message because you are subscribed to the Google Groups "SoundCloudAPI" group.
To post to this group, send email to soundc...@googlegroups.com.
To unsubscribe from this group, send email to soundcloudap...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/soundcloudapi?hl=en.

Dilip Reddy

unread,
Mar 27, 2012, 4:10:31 PM3/27/12
to SoundCloudAPI
Thank you for quick reply. However I tried that before, still i
couldn't get redirected to redirect_uri. I'm able to get 'code' on
eclipse IDE console. I'm confused how to get access token from 'code'
as I couldn't get redirected. Should I write the code for access token
in the same program?


Regards


On Mar 27, 12:41 pm, Paul Osman <os...@soundcloud.com> wrote:
> Hi Dilip,
>
> Looks like you're assigning to client.authorize_url. This isn't correct. After creating the Client instance, 'authorize_url' is a method you can use to get the URL you want to redirect your user to. Here's a corrected snippet:
>
> @route('/soundcloud/connected')
> def soundcloudapp():
>     client = soundcloud.Client(client_id='MY CLIENT ID', client_secret='MY CLIENT SECRET', redirect_uri='http://localhost:3000/soundcloud/connected')
>     return redirect(client.authorize_url())
>
> That should at least get you started. Hope that helps.
>
> Cheers,
> --
> Paul Osman
> Developer Evangelist
>
> http://soundcloud.com/paulosmanhttp://twitter.com/paulosman
> > To post to this group, send email to soundc...@googlegroups.com (mailto:soundc...@googlegroups.com).
> > To unsubscribe from this group, send email to soundcloudap...@googlegroups.com (mailto:soundcloudap...@googlegroups.com).

Paul Osman

unread,
Mar 27, 2012, 4:55:11 PM3/27/12
to soundc...@googlegroups.com
I'm not sure I fully understand the problem you're having. I'm not that familiar with Bottle, but the basic idea for authenticating a web app is:

* User visits your login URL (e.g. /login)
* User is redirected to SoundCloud to approve authorization request
* User is redirected to the URL you provided as 'redirect_uri' with a 'code' parameter appended to the query string.
* Your app exchanges the 'code' for an access token. 

Translated into rough code, that'd be something like this:


Does that clear things up at all? 

Cheers,
-- 
Paul Osman
Developer Evangelist


SoundCloud HQ USA
San Francisco CA, 94110
To post to this group, send email to soundc...@googlegroups.com.
To unsubscribe from this group, send email to soundcloudap...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages