<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Cannot authenticate to Spotify API with Node.JS app in Spotify for Developers</title>
    <link>https://community.spotify.com/t5/Spotify-for-Developers/Cannot-authenticate-to-Spotify-API-with-Node-JS-app/m-p/5020779#M975</link>
    <description>&lt;P&gt;&lt;STRONG&gt;Plan&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Free&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Country&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;CH&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Programming Language&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Node.JS 12.13.0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Question or Issue&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm creating a bot using the Spotify API. This bot should update one of my playlist by adding a specific song.&lt;/P&gt;&lt;P&gt;My problem is that I cannot obtain an access token with the /authorize endpoint.&lt;/P&gt;&lt;P&gt;Here's my code :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function getToken() {
    let generateRandomString = function (length) {
        let text = '';
        let possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

        for (let i = 0; i &amp;lt; length; i++) {
            text += possible.charAt(Math.floor(Math.random() * possible.length));
        }
        return text;
    };

    let spotifyApi = new SpotifyWebApi({
        clientId: data.spotify.client_id,
        redirectUri: data.spotify.redirect_uri
    });

    /**
     * Authenticating the app to Spotify Web API
     * @type {string[]}
     */
    let scopes = ['user-read-private', 'user-read-email', 'playlist-modify-public'],
        state = generateRandomString(16);

    // Create the authorization URL
    let authorizeURL = spotifyApi.createAuthorizeURL(scopes, state, false);

//Obtained URL -&amp;gt; https://accounts.spotify.com/authorize?client_id=516af068412341e69675da2c0f364846&amp;amp;response_type=code&amp;amp;redirect_uri=http://localhost:8888/callback&amp;amp;scope=user-read-private%20user-read-email%20playlist-modify-public&amp;amp;state=SEdtlgsP8aECVurs&amp;amp;show_dialog=false

    // Create request to the callback Express route
    https.get(authorizeURL, response =&amp;gt; {
        if (response) {
            return console.log(response);
        }
    }).on('error', err =&amp;gt; {
        console.error(err);
    });
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I process the GET request to authenticate my app (see the https.get part above) and when I check what is given in my console (output given by the return console.log(response)), I get that :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;...
responseUrl: 'https://accounts.spotify.com/login?continue=https%3A%2F%2Faccounts.spotify.com%2Fauthorize%3Fscope%3Duser-read-private%2Buser-read-email%2Bplaylist-modify-public%26response_type%3Dcode%26redirect_uri%3Dhttp%253A%252F%252Flocalhost%253A8888%252Fcallback%26state%3DlD3Ijyz5ucTZ9L5B%26client_id%3D516af068412341e69675da2c0f364846%26show_dialog%3Dfalse',
...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the reponse URL I have. It seems that I'm not logged, thus I cannot access the Spotify Web API.&lt;/P&gt;&lt;P&gt;My callback route is working since I can copy/paste the authorizeUrl in a browser, and I'll get the token written in a text file. It's only when I try to process a request with https.get that it doesn't work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the API prompt me for login, then why is there an CLIENT_ID and CLIENT_SECRET since there not used ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT : fixed obtained&amp;nbsp;URL since it wasn't what I obtained ^^&lt;/P&gt;</description>
    <pubDate>Thu, 20 Aug 2020 15:50:46 GMT</pubDate>
    <dc:creator>LeRouteur</dc:creator>
    <dc:date>2020-08-20T15:50:46Z</dc:date>
    <item>
      <title>Cannot authenticate to Spotify API with Node.JS app</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Cannot-authenticate-to-Spotify-API-with-Node-JS-app/m-p/5020779#M975</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Plan&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Free&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Country&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;CH&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Programming Language&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Node.JS 12.13.0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Question or Issue&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm creating a bot using the Spotify API. This bot should update one of my playlist by adding a specific song.&lt;/P&gt;&lt;P&gt;My problem is that I cannot obtain an access token with the /authorize endpoint.&lt;/P&gt;&lt;P&gt;Here's my code :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function getToken() {
    let generateRandomString = function (length) {
        let text = '';
        let possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

        for (let i = 0; i &amp;lt; length; i++) {
            text += possible.charAt(Math.floor(Math.random() * possible.length));
        }
        return text;
    };

    let spotifyApi = new SpotifyWebApi({
        clientId: data.spotify.client_id,
        redirectUri: data.spotify.redirect_uri
    });

    /**
     * Authenticating the app to Spotify Web API
     * @type {string[]}
     */
    let scopes = ['user-read-private', 'user-read-email', 'playlist-modify-public'],
        state = generateRandomString(16);

    // Create the authorization URL
    let authorizeURL = spotifyApi.createAuthorizeURL(scopes, state, false);

//Obtained URL -&amp;gt; https://accounts.spotify.com/authorize?client_id=516af068412341e69675da2c0f364846&amp;amp;response_type=code&amp;amp;redirect_uri=http://localhost:8888/callback&amp;amp;scope=user-read-private%20user-read-email%20playlist-modify-public&amp;amp;state=SEdtlgsP8aECVurs&amp;amp;show_dialog=false

    // Create request to the callback Express route
    https.get(authorizeURL, response =&amp;gt; {
        if (response) {
            return console.log(response);
        }
    }).on('error', err =&amp;gt; {
        console.error(err);
    });
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I process the GET request to authenticate my app (see the https.get part above) and when I check what is given in my console (output given by the return console.log(response)), I get that :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;...
responseUrl: 'https://accounts.spotify.com/login?continue=https%3A%2F%2Faccounts.spotify.com%2Fauthorize%3Fscope%3Duser-read-private%2Buser-read-email%2Bplaylist-modify-public%26response_type%3Dcode%26redirect_uri%3Dhttp%253A%252F%252Flocalhost%253A8888%252Fcallback%26state%3DlD3Ijyz5ucTZ9L5B%26client_id%3D516af068412341e69675da2c0f364846%26show_dialog%3Dfalse',
...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the reponse URL I have. It seems that I'm not logged, thus I cannot access the Spotify Web API.&lt;/P&gt;&lt;P&gt;My callback route is working since I can copy/paste the authorizeUrl in a browser, and I'll get the token written in a text file. It's only when I try to process a request with https.get that it doesn't work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the API prompt me for login, then why is there an CLIENT_ID and CLIENT_SECRET since there not used ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT : fixed obtained&amp;nbsp;URL since it wasn't what I obtained ^^&lt;/P&gt;</description>
      <pubDate>Thu, 20 Aug 2020 15:50:46 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Cannot-authenticate-to-Spotify-API-with-Node-JS-app/m-p/5020779#M975</guid>
      <dc:creator>LeRouteur</dc:creator>
      <dc:date>2020-08-20T15:50:46Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot authenticate to Spotify API with Node.JS app</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Cannot-authenticate-to-Spotify-API-with-Node-JS-app/m-p/5091645#M1705</link>
      <description>&lt;P&gt;Hey man, how did you get your RedirectURI, i have been getting INVALID RedirectURI on my ReactNative expo app&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 21:50:48 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Cannot-authenticate-to-Spotify-API-with-Node-JS-app/m-p/5091645#M1705</guid>
      <dc:creator>michaeldaralola</dc:creator>
      <dc:date>2020-12-11T21:50:48Z</dc:date>
    </item>
  </channel>
</rss>

