我想将soundcloud小部件添加到我的应用程序。 为此,我需要在iframe src上发送参数。 问题在于,soundcloud需要TrackID而不是曲目的URL地址,并且我的用户无法在Soundcloud的UI上找到此trackID。 如何通过跟踪URL地址解析TrackID?
如果仅通过使用API可以实现-那么如何注册为新应用?现在看来不可能了。另外,我需要进行什么API调用才能解决此信息?
谢谢。
答案 0 :(得分:1)
就像您需要从soundcloud网址中获取一些曲目信息一样,但是从我这一角度来看,无法选择使用API(自2017年以来API已关闭)。这是我想出的获取曲目ID的方法。
<?php
// url test example
$url = "https://soundcloud.com/the-bugle/bugle-179-playas-gon-play";
// this link give some infos of the track
$infos_music_soundcloud = 'https://soundcloud.com/oembed?url='.urlencode($url).'&format=json';
$page_content = file_get_contents($infos_music_soundcloud);
if(!empty($page_content)){
$content = json_decode($page_content);
// now, the track ID is in the html iframe code. Lets get it.
$matches = array();
preg_match('/tracks%2F(.*?)&/s', $content->{'html'}, $matches);
echo "the track id is ".$matches[1];
}else{
echo "the track don't seems to exists. Please verify the link";
}
?>
您还可以获取标题,描述,缩略图,作者姓名/网址... 希望能有所帮助;)
编辑- 如果该曲目是私人曲目,则只需确保提供私人链接(即末尾带有“ / s-clUrZ”之类的文字)
答案 1 :(得分:0)
Soundcloud具有可以被调用以解析URL的API。
如果您拥有有效的client_id
,则可以执行GET请求,并将url
和client_id
设置为参数。
https://api.soundcloud.com/resolve.json?url=https://soundcloud.com/tomer-maizner/forever-tel-aviv-pride-2018-anthems-mixed-by-tomer-maizner&client_id=CLIENT_ID
这将给您以下答复:
{
kind: "track",
id: 460976748,
created_at: "2018/06/20 16:25:14 +0000",
user_id: 8504856,
duration: 3570385,
commentable: true,
state: "finished",
original_content_size: 142800123,
last_modified: "2018/06/23 15:26:59 +0000",
sharing: "public",
tag_list: ""forever tel aviv" circuit "we party" mix pride "tel aviv"",
permalink: "forever-tel-aviv-pride-2018-anthems-mixed-by-tomer-maizner",
streamable: true,
embeddable_by: "all",
purchase_url: null,
purchase_title: null,
label_id: null,
genre: "Electronic",
title: "Forever Tel-Aviv - Pride 2018 Anthems (Mixed By Tomer Maizner)",
description: "The best of the best from the pride weekend in Tel-Aviv including tracks from all Forever Tel-Aviv superstars . Sagi Kariv / Tomer Maizner / Yinon Yahel / Tommer Mizrahi / Mor Avrahami / Elad Navon / Micky Friedman Enjoy!!! Tracklist : 1. Tomer Maizner Feat. Madame Meyhem - Unbreak My Heart 2018 2. N-Trance - Set You Free (Sagi Kariv remix) 3. Maître Gims – Mi Gna (Tommer Mizrahi Remix) 4. Micky Friedman - Eshebo feat Hila Ben Saadon (Original Mix) 5. Edson Pride - Freedom (Tomer Maizner Stanga Mash) 6. Netta - Toy (Sagi Kariv extended remix) 7. Arian Grande - No Tears Left To Cry Remix (DJ Aron Remix) 8. Steven Redant - Sunshine On My Shoulders (Tommer Mizrahi Remix) 9. Mor Avrahami - Kumei (Original Mix) 10 . Sissy That B.Y.O.B (Tomer Maizner Mashup) 11. Louie Vega - Diamond Life (Elad Navon & Niv Aroya Remix) 12. Hanna Hais - Je Ne Veux Plus Etre Ta Reine (Ranz Remix) 13. I Am Free (Yinon Yahel Remix)",
label_name: null,
release: null,
track_type: null,
key_signature: null,
isrc: null,
video_url: null,
bpm: null,
release_year: null,
release_month: null,
release_day: null,
original_format: "mp3",
license: "all-rights-reserved",
uri: "https://api.soundcloud.com/tracks/460976748",
user: {
id: 8504856,
kind: "user",
permalink: "tomer-maizner",
username: "TOMER MAIZNER",
last_modified: "2018/06/20 17:34:39 +0000",
uri: "https://api.soundcloud.com/users/8504856",
permalink_url: "http://soundcloud.com/tomer-maizner",
avatar_url: "https://i1.sndcdn.com/avatars-000234677748-voqr8o-large.jpg"
},
permalink_url: "https://soundcloud.com/tomer-maizner/forever-tel-aviv-pride-2018-anthems-mixed-by-tomer-maizner",
artwork_url: "https://i1.sndcdn.com/artworks-000363076815-gwll9g-large.jpg",
stream_url: "https://api.soundcloud.com/tracks/460976748/stream",
download_url: "https://api.soundcloud.com/tracks/460976748/download",
playback_count: 8696,
download_count: 0,
favoritings_count: 792,
reposts_count: 62,
comment_count: 5,
downloadable: false,
waveform_url: "https://w1.sndcdn.com/WoEUY48eF4tR_m.png",
attachments_uri: "https://api.soundcloud.com/tracks/460976748/attachments"
}
答案 2 :(得分:0)
不幸的是,SoundCloud API无限期不接受新注册。像上面的评论一样,一个简单的替代解决方案是,如果您使用此URL,它将为您提供宽/短播放器:
https://w.soundcloud.com/player/?url=
+曲目的网址
示例:https://w.soundcloud.com/player/?url=https://soundcloud.com/chrisbjerken/you-still-have-my-heart
这适用于单个曲目或播放列表。