如何使用SoundCloudAPI从URL获取曲目ID
如何使用SoundCloud API从曲目URL获取曲目ID?您的问题中没有指定语言,因此我将提供一个高级答案 使用如何使用SoundCloudAPI从URL获取曲目ID,api,url,soundcloud,Api,Url,Soundcloud,如何使用SoundCloud API从曲目URL获取曲目ID?您的问题中没有指定语言,因此我将提供一个高级答案 使用解析端点。我以这个URL为例: 生成的JSON: { "status": "302 - Found", "location": "https://api.soundcloud.com/tracks/147986343.json?client_id=[YOUR client_id]" } 该数值是轨迹id。您可以停在此处或点击刚刚返回的端点以获取更多信息: { "ki
解析
端点。我以这个URL为例:
生成的JSON:
{
"status": "302 - Found",
"location": "https://api.soundcloud.com/tracks/147986343.json?client_id=[YOUR client_id]"
}
该数值是轨迹id
。您可以停在此处或点击刚刚返回的端点以获取更多信息:
{
"kind": "track",
"id": 90787841,
"created_at": "2013/05/05 00:15:40 +0000",
"user_id": 7853935,
"duration": 188333,
"commentable": true,
"state": "finished",
"original_content_size": 35031144,
"last_modified": "2014/09/30 05:53:10 +0000",
"sharing": "public",
"tag_list": "MSMR CHVRCHES \"Secondhand Rapture\" Remix Hurricane",
"permalink": "ms-mr-hurricane-chvrches-remix",
"streamable": true,
"embeddable_by": "all",
"downloadable": true,
"purchase_url": null,
"label_id": null,
"purchase_title": null,
"genre": "",
"title": "MS MR - Hurricane (CHVRCHES remix)",
"description": "MS MR - Hurricane (CHVRCHES remix)\r\n\r\n\r\n",
"label_name": "",
"release": "",
"track_type": "",
"key_signature": "",
"isrc": "",
"video_url": null,
"bpm": null,
"release_year": null,
"release_month": null,
"release_day": null,
"original_format": "wav",
"license": "all-rights-reserved",
"uri": "https://api.soundcloud.com/tracks/90787841",
"user": {
"id": 7853935,
"kind": "user",
"permalink": "msmrsounds",
"username": "MSMR",
"last_modified": "2014/08/04 09:03:56 +0000",
"uri": "https://api.soundcloud.com/users/7853935",
"permalink_url": "http://soundcloud.com/msmrsounds",
"avatar_url": "https://i1.sndcdn.com/avatars-000037198343-2lptmy-large.jpg?86347b7"
},
"permalink_url": "http://soundcloud.com/msmrsounds/ms-mr-hurricane-chvrches-remix",
"artwork_url": null,
"waveform_url": "https://w1.sndcdn.com/56LCadzDEBZn_m.png",
"stream_url": "https://api.soundcloud.com/tracks/90787841/stream",
"download_url": "https://api.soundcloud.com/tracks/90787841/download",
"playback_count": 1672227,
"download_count": 18494,
"favoritings_count": 20426,
"comment_count": 464,
"attachments_uri": "https://api.soundcloud.com/tracks/90787841/attachments",
"policy": "ALLOW"
}
我最后的代码是这样的。谢谢你们的帮助,让这一切顺利进行
include_once('../Services/Soundcloud.php');
$client = new Services_Soundcloud('CLIENT_ID', 'CLIENT_SECRET');
$track_url=$_POST['trackurl'];
$track_url=str_replace("https://soundcloud.com/USERNAME/","",$track_url);
$track = json_decode($client->get("tracks/".$track_url));
$track_id=$track->id;
echo $track_id;
在写这个答案的同时,客户的ID已经接近了 由于最近收到了大量请求,我们现在将不再处理API应用程序请求。我们正在努力重新评估我们的流程,使其更有效率 看 我用我的Laravel项目解决了这个问题 首先,我做这个函数是为了得到真正的内容
public function getLessonUrl($lessonId = null)
{
//Get the SoundCloud URL
$validUrl = 'https://soundcloud.com/al-hazme';
$result = stripos($lessonId, $validUrl);
if (strpos($lessonId, $validUrl) !== false) {
//Get the JSON data details with embed code from SoundCloud oEmbed
$getValues = @file_get_contents('http://soundcloud.com/oembed?format=js&url=' . $lessonId . '&color=%234274e3&auto_play=false&hide_related=true&show_comments=false&show_user=false&show_reposts=false&show_teaser=true&show_artwork');
if ($getValues === false) {
return 'حدث خطأ اثناء تحميل الدرس نرجو منك التأكد من اتصال الانترنيت لديك او حدث الصفحة';
}
//Clean the Json to decode
$decodeiFrame = substr($getValues, 1, -2);
//json decode to convert it as an array
$jsonObj = json_decode($decodeiFrame);
//echo $jsonObj->html;
$lessons = str_replace('height="400"', 'height="90"', $jsonObj->html);
return $lessons;
} else {
return 'لايوجد استماع لهذا الدرس';
}
}
然后,我使用strfacade方法创建了另一个函数来丢弃Id
use Illuminate\Support\Str;
public function soundCloudId($url) {
$do = $lesson->getLessonUrl($lesson->url_link);
$getTrickId = Str::after($do,'tracks%2F');
$substr = Str::substr($getTrickId,0,9);
echo $substr = // 367893857
}
由于SoundCloud API无限期地不接受新的注册,它可能会帮助您或为您提供线索,这里有一个替代解决方案。此URL将为您提供宽/短嵌入式播放器:
https://w.soundcloud.com/player/?url=
+曲目的URL
例如:
这对单曲或播放列表都有效。我知道这有点晚了,但我昨天遇到了同样的问题,找到了一个新的(未记录的)端点,可以使用
https://api-widget.soundcloud.com/resolve?url=SOUNDLCOUD_URL&format=json&client_id=CLIENT_ID
在浏览SoundCloud网站时,您可以通过查看DevTools中的Network Inspector并选择XHR过滤器,找到您的客户端ID
在官方API再次可用之前,我认为这已经足够了。非常感谢您。。。顺便说一句,它是用PHP编写的。我刚刚用json_decode()函数解决了这个问题。不幸的是,SoundCloud在2017年7月左右关闭了API注册。此方法仅适用于在此之前注册的用户。有关API注册的进一步参考,请参见当前链接,其中显示“我们此时将不再处理API应用程序请求”。相关信息,适用于寻求反向操作的用户:
https://api-widget.soundcloud.com/resolve?url=SOUNDLCOUD_URL&format=json&client_id=CLIENT_ID