通过 spotify API 提取 Preview_Url

Extract Preview_Url through spotify API

嗯,我打算通过 Spotify API 提取函数 preview_url 但是我无法在代码后面找到这个函数,所以我来寻求你的帮助。

"preview_url" : "https://p.scdn.co/mp3-preview/5dcd99cf811094408dcfc1befe014495d786dab5",

{
  "artists" : {
    "href" : "https://api.spotify.com/v1/search?query=MAROON+5+ANIMALS&offset=0&limit=1&type=artist",
    "items" : [ ],
    "limit" : 1,
    "next" : null,
    "offset" : 0,
    "previous" : null,
    "total" : 0
  },
  "tracks" : {
    "href" : "https://api.spotify.com/v1/search?query=MAROON+5+-+ANIMALS&offset=0&limit=1&type=track",
    "items" : [ {
      "album" : {
        "album_type" : "album",
        "artists" : [ {
          "external_urls" : {
            "spotify" : "https://open.spotify.com/artist/04gDigrS5kc9YWfZHwBETP"
          },
          "href" : "https://api.spotify.com/v1/artists/04gDigrS5kc9YWfZHwBETP",
          "id" : "04gDigrS5kc9YWfZHwBETP",
          "name" : "Maroon 5",
          "type" : "artist",
          "uri" : "spotify:artist:04gDigrS5kc9YWfZHwBETP"
        } ],
        "available_markets" : [ "CA", "MX", "US" ],
        "external_urls" : {
          "spotify" : "https://open.spotify.com/album/2Auw0pTT6EcQdvHNimhLQI"
        },
        "href" : "https://api.spotify.com/v1/albums/2Auw0pTT6EcQdvHNimhLQI",
        "id" : "2Auw0pTT6EcQdvHNimhLQI",
        "images" : [ {
          "height" : 640,
          "url" : "https://i.scdn.co/image/4c23a82f33b034795a0fbc67af559420c8cb4928",
          "width" : 640
        }, {
          "height" : 300,
          "url" : "https://i.scdn.co/image/44b0e6423240ed25f36f351ae043f68bb2ca3446",
          "width" : 300
        }, {
          "height" : 64,
          "url" : "https://i.scdn.co/image/2e8ff05c6f96006130bbc64ef0b42b402252ace8",
          "width" : 64
        } ],
        "name" : "V",
        "type" : "album",
        "uri" : "spotify:album:2Auw0pTT6EcQdvHNimhLQI"
      },
      "artists" : [ {
        "external_urls" : {
          "spotify" : "https://open.spotify.com/artist/04gDigrS5kc9YWfZHwBETP"
        },
        "href" : "https://api.spotify.com/v1/artists/04gDigrS5kc9YWfZHwBETP",
        "id" : "04gDigrS5kc9YWfZHwBETP",
        "name" : "Maroon 5",
        "type" : "artist",
        "uri" : "spotify:artist:04gDigrS5kc9YWfZHwBETP"
      } ],
      "available_markets" : [ "CA", "MX", "US" ],
      "disc_number" : 1,
      "duration_ms" : 231012,
      "explicit" : false,
      "external_ids" : {
        "isrc" : "USUM71409576"
      },
      "external_urls" : {
        "spotify" : "https://open.spotify.com/track/2bL2gyO6kBdLkNSkxXNh6x"
      },
      "href" : "https://api.spotify.com/v1/tracks/2bL2gyO6kBdLkNSkxXNh6x",
      "id" : "2bL2gyO6kBdLkNSkxXNh6x",
      "name" : "Animals",
      "popularity" : 69,
      "preview_url" : "https://p.scdn.co/mp3-preview/5dcd99cf811094408dcfc1befe014495d786dab5",
      "track_number" : 2,
      "type" : "track",
      "uri" : "spotify:track:2bL2gyO6kBdLkNSkxXNh6x"
    } ],
    "limit" : 1,
    "next" : "https://api.spotify.com/v1/search?query=MAROON+5+-+ANIMALS&offset=1&limit=1&type=track",
    "offset" : 0,
    "previous" : null,
    "total" : 99
  }
}

允许我实现所需功能的代码

$get_json->tracks->items[0]->artists[1]->external_urls->preview_url;

你能帮帮我吗?谢谢!

您似乎没有找到 preview_url 值的正确路径。实际路径是tracks->items[0]->preview_url。希望这在某种程度上有所帮助。