Get Soundcloud URL for a track using only its ID

狂风中的少年 提交于 2019-12-04 04:11:34

问题


I've inherited a database of Soundcloud IDs and would like to build a page linking to each track on Soundcloud. Is it possible to link to a track on the Soundcloud website using only its ID e.g.

http://www.soundcloud.com/tracks/{trackId}

The website seems to use the format:

http://www.soundcloud.com/{user}/{trackname}

but I don't have either of those.


回答1:


You can scrape it from the "widget" URL

https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/{trackId}

contains a link element

<link rel="canonical" href="{canonicalURI}">



回答2:


It seems that the way to do this is to use the API. With a track number, you can call

http://api.soundcloud.com/tracks/12345678.json?client_id=YOUR_CLIENT_ID

This returns a JSON object with a permalink_url property which gives you the full url including the user and track name.

See the API tracks documentation for more details.




回答3:


First you will need to register an app at https://soundcloud.com/you/apps.

Then use the API to return a JSON object of the track using the track ID and your client ID.

e.g. (using jQuery) …

$.ajax({ url: "http://api.soundcloud.com/playlists/405726.json?client_id=XXXX", type: 'GET', success: function (data) { console.log(data); } });

Where XXX is your Client ID.



来源:https://stackoverflow.com/questions/29495775/get-soundcloud-url-for-a-track-using-only-its-id

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!