【问题标题】:Is there any way to get sound cloud Track ID by Share URL?有没有办法通过共享 URL 获取 soundcloud Track ID?
【发布时间】:2018-09-21 10:25:42
【问题描述】:
  1. 有一个文本输入框可以传递SoundCloud的“分享”URL。
  2. “分享”网址示例:https://soundcloud.com/alo-wala/the-coconut-song
  3. WordPress 使用相同的 URL 来生成 IFRAME/Embed 代码,如果我们在可视化编辑器中粘贴共享 URL...
  4. 现在我们有了另一个选项,可以按照IFRAME 代码在任何网站上嵌入 SoundCloud 小部件。
  5. 示例 IFRAME 代码:<iframe width="100%" height="300" scrolling="no" frameborder="no" allow="autoplay" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/203809866&color=%23ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&show_teaser=true&visual=true"></iframe>
  6. 现在,如果您观察 SRC,它具有唯一的轨道 ID 值:https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/203809866
  7. 其余参数对于任何嵌入代码都将保持不变

我的要求: 我想使用“共享”URL 作为输入来生成 Track ID,这与 WordPress 使用 oEmbed 功能的方式完全相同,用于我自己的自定义字段。

请注意,我没有使用 ACF。

提前致谢:)

【问题讨论】:

    标签: wordpress api iframe embed soundcloud


    【解决方案1】:

    您可以通过 SoundCloud 的 JS API 获取任何歌曲的曲目 ID:

    <script src="https://connect.soundcloud.com/sdk/sdk-3.3.0.js"></script>
    <script>
    SC.initialize({
      client_id: 'YOUR_CLIENT_ID'
    });
    
    // permalink to a track
    var track_url = 'https://soundcloud.com/alo-wala/the-coconut-song';
    
    var myCustomFunction = function (track) {
      console.log( track ); // track.id gives you the ID of the song
    
      // @TODO
      // Do something with the song ID
    };
    
    SC.resolve(track_url).then(myCustomFunction);
    </script>
    

    YOUR_CLIENT_ID 替换为您的SoundCloud App 的ID。

    更多详情:SoundCloud API - Guide - SoundCloud URLs.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-14
      • 1970-01-01
      • 2022-01-07
      • 1970-01-01
      • 2021-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多