title: Spotify API php - unable to request data and get access token
body: <p>I am currently new to using php and Laravel and working with an API however I have been following the Spotify PHP tutorial <a href="https://github.com/jwilsson/spotify-web-api-php" rel="nofollow noreferrer">https://github.com/jwilsson/spotify-web-api-php</a>. </p>
  
  <p>I've also put in bold some of my questions that I wanted to ask , hopefully someone can help.</p>
  
  <p>I have followed all steps but need help just to get it working.</p>
  
  <p>Put the following code in its own file, lets call it auth.php. Replace CLIENT_ID and CLIENT_SECRET with the values given to you by Spotify.</p>
  
  <p><strong>(Where abouts should I save this file?)</strong></p>
  
  <p>The REDIRECT_URI is the one you entered when creating the Spotify app, make sure it's an exact match.</p>
  
  <p><strong>(I used my localhost:8888/callback/ not sure if that is correct?) Obviously I haven't put me details in here on this website as for security reasons.</strong> </p>
  
  <pre><code>&lt;?php
  require 'vendor/autoload.php';
  
  $session = new SpotifyWebAPI\Session(
      'CLIENT_ ID',
      'CLIENT_SECRET',
      'REDIRECT_URL'
  );
  
  $options = [
      'scope' =&gt; [
          'playlist-read-private',
          'user-read-private',
      ],
  ];
  
  header('Location: ' . $session-&gt;getAuthorizeUrl($options));
  die();
  
  
  
  ?&gt;
  </code></pre>
  
  <p>When the user has approved your app, Spotify will redirect the user together with a code to the specifed redirect URI. You'll need to use this code to request a access token from Spotify.</p>
  
  <p>put this code in a new file called callback.php:</p>
  
  <p>Do replace client id and secret with my detail? also how do I save the access token?</p>
  
  <pre><code>require 'vendor/autoload.php';
  
  $session = new SpotifyWebAPI\Session(
      'CLIENT_ID',
      'CLIENT_SECRET',
      'REDIRECT_URI'
  );
  
  // Request a access token using the code from Spotify
  $session-&gt;requestAccessToken($_GET['code']);
  
  $accessToken = $session-&gt;getAccessToken();
  $refreshToken = $session-&gt;getRefreshToken();
  
  // Store the access and refresh tokens somewhere. In a database for example.
  
  // Send the user along and fetch some data!
  header('Location: app.php');
  die();
  </code></pre>
  
  <p>In a third file, app.php, tell the API wrapper which access token to use, and then make some API calls! </p>
  
  <p><strong>(Where do i also save this file and how do I make these calls in my Laravel Controllers?)</strong></p>
  
  <pre><code>require 'vendor/autoload.php';
  
  $api = new SpotifyWebAPI\SpotifyWebAPI();
  
  // Fetch the saved access token from somewhere. A database for example.
  $api-&gt;setAccessToken($accessToken);
  
  // It's now possible to request data about the currently authenticated user
  print_r(
      $api-&gt;me()
  );
  
  // Getting Spotify catalog data is of course also possible
  print_r(
      $api-&gt;getTrack('7EjyzZcbLxW7PaaLua9Ksb')
  );
  </code></pre>