question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Preview URL is always null, even for available markets

See original GitHub issue

Tried a number of IDs and keep getting preview_url: null. When using the ID directly from the API documentation, it returns the preview URL.

I don’t think it matters since it’s just a wrapper, but I’m using the node.js version.

The function call:

spotifyApi.getTrack('2cWBwpqMsDJC1ZUwz813lo',
        function(err, data) {
            if (err) {
                console.error('Something went wrong!');
            } else {
                result = data.body;
            }
        }
    );

The returned JSON.

{
  album: {
    album_type: 'album',
    artists: [ [Object] ],
    available_markets: [
      'AD', 'AE', 'AR', 'AT', 'AU', 'BE', 'BG', 'BH',
      'BO', 'BR', 'CA', 'CH', 'CL', 'CO', 'CR', 'CY',
      'CZ', 'DE', 'DK', 'DO', 'DZ', 'EC', 'EE', 'EG',
      'ES', 'FI', 'FR', 'GB', 'GR', 'GT', 'HK', 'HN',
      'HU', 'ID', 'IE', 'IL', 'IN', 'IS', 'IT', 'JO',
      'JP', 'KW', 'LB', 'LI', 'LT', 'LU', 'LV', 'MA',
      'MC', 'MT', 'MX', 'MY', 'NI', 'NL', 'NO', 'NZ',
      'OM', 'PA', 'PE', 'PH', 'PL', 'PT', 'PY', 'QA',
      'RO', 'SA', 'SE', 'SG', 'SK', 'SV', 'TH', 'TN',
      'TR', 'TW', 'US', 'UY', 'VN', 'ZA'
    ],
    external_urls: {
      spotify: 'https://open.spotify.com/album/2cWBwpqMsDJC1ZUwz813lo'
    },
    href: 'https://api.spotify.com/v1/albums/2cWBwpqMsDJC1ZUwz813lo',
    id: '2cWBwpqMsDJC1ZUwz813lo',
    images: [ [Object], [Object], [Object] ],
    name: 'The Eminem Show',
    release_date: '2002-05-26',
    release_date_precision: 'day',
    total_tracks: 20,
    type: 'album',
    uri: 'spotify:album:2cWBwpqMsDJC1ZUwz813lo'
  },
  artists: [
    {
      external_urls: [Object],
      href: 'https://api.spotify.com/v1/artists/7dGJo4pcD2V6oG8kP0tJRR',
      id: '7dGJo4pcD2V6oG8kP0tJRR',
      name: 'Eminem',
      type: 'artist',
      uri: 'spotify:artist:7dGJo4pcD2V6oG8kP0tJRR'
    },
    {
      external_urls: [Object],
      href: 'https://api.spotify.com/v1/artists/1Oa0bMld0A3u5OTYfMzp5h',
      id: '1Oa0bMld0A3u5OTYfMzp5h',
      name: 'Nate Dogg',
      type: 'artist',
      uri: 'spotify:artist:1Oa0bMld0A3u5OTYfMzp5h'
    }
  ],
  available_markets: [
    'AD', 'AE', 'AR', 'AT', 'AU', 'BE', 'BG', 'BH',
    'BO', 'BR', 'CA', 'CH', 'CL', 'CO', 'CR', 'CY',
    'CZ', 'DE', 'DK', 'DO', 'DZ', 'EC', 'EE', 'EG',
    'ES', 'FI', 'FR', 'GB', 'GR', 'GT', 'HK', 'HN',
    'HU', 'ID', 'IE', 'IL', 'IN', 'IS', 'IT', 'JO',
    'JP', 'KW', 'LB', 'LI', 'LT', 'LU', 'LV', 'MA',
    'MC', 'MT', 'MX', 'MY', 'NI', 'NL', 'NO', 'NZ',
    'OM', 'PA', 'PE', 'PH', 'PL', 'PT', 'PY', 'QA',
    'RO', 'SA', 'SE', 'SG', 'SK', 'SV', 'TH', 'TN',
    'TR', 'TW', 'US', 'UY', 'VN', 'ZA'
  ],
  disc_number: 1,
  duration_ms: 297786,
  explicit: true,
  external_ids: { isrc: 'USIR10211066' },
  external_urls: { spotify: 'https://open.spotify.com/track/4xkOaSrkexMciUUogZKVTS' },
  href: 'https://api.spotify.com/v1/tracks/4xkOaSrkexMciUUogZKVTS',
  id: '4xkOaSrkexMciUUogZKVTS',
  is_local: false,
  name: "'Till I Collapse",
  popularity: 85,
  preview_url: null,
  track_number: 18,
  type: 'track',
  uri: 'spotify:track:4xkOaSrkexMciUUogZKVTS'
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
kevinguebertcommented, Nov 26, 2019

Yeah, that’s super weird. I may dig into it more as I am trying to understand the use case for not providing it with client credentials. Maybe since it never refreshes or times out, someone could abuse that token and preview URL?

Nothing open-sourced right now, unfortunately. Depending on your project and if you need user authentication or not, there is a passport.js helper for Spotify that’s pretty easy. I currently use Firebase with Firebase Functions for my Spotify auth. That is all requiring multiple user accounts though…hm for you I would maybe look into https://github.com/thelinmichael/spotify-web-api-node and putting your access token on a server that refreshes it. Then instead of making calls directly to the Spotify API from your web app, you would call your server API that handles the Spotify API request. I’m not a security expert though so don’t quote me on that 🙃

1reaction
kevinguebertcommented, Nov 26, 2019

Ohh looks like you did catch something. I did not receive back a preview_url from my client credentials but I did receive one from my user flow. That’s strange but it looks like you may have to go with your refresh token solution

Read more comments on GitHub >

github_iconTop Results From Across the Web

preview_url doesn't give an url anymore
Today it doesn't work anymore, every song has the preview_url = null. I can get every info of a track, like the image,...
Read more >
API - get track - Preview URL is NULL? : r/spotify - Reddit
Hello,. Retrieving a track JSON data using the dev web API sometimes returns a value of "NULL" for "preview_URL".
Read more >
Common Survey Errors - Qualtrics
Another way to think of it is this: display logic cannot look into the future and tell what respondents will say to a...
Read more >
Troubleshooting link issues - Squarespace Help Center
Most issues with links on Squarespace sites happen when there are errors with the linked URL. You can resolve many of these errors...
Read more >
Health coverage application tips & troubleshooting
null Tips and Troubleshooting for using Healthcare.gov, including applying for an enrolling in health coverage.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found