Search code examples
apispotifyspotify-app

Spotify API - can get my own data, but can't get a user's data if the user is not a registered Spotify API developer


<script>
    /*  */
    import axios from 'axios';
    import {onMount} from 'svelte';
    let root;
    let token;
    let tokentype;
    let CLIENT_ID = 'e4786b5e94404f12958b48fbb6301176';
    let SPOTIFY_AUTHORIZE_ENDPOINT = 'https://accounts.spotify.com/authorize';
    let REDIRECT_URI_AFTER_LOGIN = 'http://localhost:8080/';
    let PLAYLISTS_ENDPOINT = 'https://api.spotify.com/v1/me/';
    let SCOPES = [
        'ugc-image-upload',
        'user-read-playback-state',
        'user-top-read',
        'user-read-recently-played',
        'playlist-read-private',
        'user-read-currently-playing'
    ];
    let SCOPES_MODIFIED = SCOPES.join('%20');
    function returnData(hash) {
        let stringAfterHashtag = hash.substring(1);
        let paramsInUrl = stringAfterHashtag.split('&');
        let paramsSplit = paramsInUrl.reduce((accumulater, currentValue) => {
            console.log(currentValue);
            let [key, value] = currentValue.split('=');
            accumulater[key] = value;

            return accumulater;
        }, {});
        return paramsSplit;
    }

    onMount(() => {
        if (window.location.hash) {
            let {access_token, token_type, expires_in} = returnData(window.location.hash);

            token = access_token;
            tokentype = token_type;
        }
    });

    function handleLogin() {
        window.location = `${SPOTIFY_AUTHORIZE_ENDPOINT}?client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URI_AFTER_LOGIN}&scopes=${SCOPES_MODIFIED}&response_type=token&show_dialog=true`;
    }

    function handleGetPlaylist() {
        axios
            .get(PLAYLISTS_ENDPOINT, {
                headers: {
                    Authorization: 'Bearer ' + token
                }
            })
            .then(res => {
                root = res.data.items;
                console.log(res.data.items);
            })
            .catch(err => {
                console.log(err);
            });
    }
</script>

Here, as you can see, I'm trying to get user playlists. When I tried it on my own account, it worked. But when I tried it on someone's account that is not registered for Spotify API, it didn't work. Here was the error User not registered in the Developer Dashboard

I want to be able to get every user's playlists if they're logged in. Please help


Solution

  • You get this error, because you'll need a quota extension to let other people use your app now.
    You can read here about this change, and read here about the different app modes.