Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the secret link for a track posted to Soundcloud in Python?

I'm developing a simple app using Python where I can post tracks to my own Soundcloud account. I would like to get the 'Secret link' URL for a track that I post. For example, I get the most recent track like so:

track = client.get('/me/tracks', limit=1)[0]

The track is set to private. It suggests in the Docs that something like this should return the secret token:

client.get('/tracks/%d/secret-token' %track.id)

However, I get HTTPError: 404 Client Error: Not Found. All the other subresources seem to work. This example code, for example, works as you would expect:

comments = client.get('/tracks/%d/comments' %track.id)

for comment in comments:
    print comment.body

I would have thought that, given that I have authenticated using my credentials, I would have access to this. Is this correct? Any assistance would be greatly appreciated.

like image 639
Mark Steadman Avatar asked Nov 12 '22 09:11

Mark Steadman


1 Answers

The /me/tracks endpoint returns a Track object that includes secret_token as well as the full uri secret_uri.

track = client.get('/me/tracks', limit=1)[0]
print "Secret Token: %s" %track.secret_token
print "Track URI: %s"  %track.secret_uri

I found I needed to include the client_id in the URI to avoid getting a 401.

Note: this is undocumented so check with their support team before relying this in an application

like image 179
osowskit Avatar answered Nov 14 '22 21:11

osowskit