简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM