title: Rendering SoundCloud widget for a private track using PHP API
body: <p>I am trying to render a SoundCloud HTML5 widget using the PHP API, but every time I run the command I think should return the HTML for the widget, I simply get an Exception:</p>
  
  <pre><code>The requested URL responded with HTTP code 302
  </code></pre>
  
  <p>I realise this is a redirect. What I don't know is why that's all I ever get, or what to do about it to actually get the widget HTML.</p>
  
  <p>The documentation on the API says that to embed the widget using PHP you should do this:</p>
  
  <pre><code>&lt;?php
      require_once 'Services/Soundcloud.php';
  
      // create a client object with your app credentials
      $client = new Services_Soundcloud('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET');
  
      // get a tracks oembed data
      $track_url = 'http://soundcloud.com/forss/flickermood';
      $embed_info = $client-&gt;get('/oembed', array('url' =&gt; $track_url));
  
      // render the html for the player widget
      print $embed_info['html'];
  </code></pre>
  
  <p>I'm running this:</p>
  
  <pre><code>// NB: Fully authorised SoundCloud API instance all working prior to this line
  // $this-&gt;api refers to an authorised instance of Services_Soundcloud
  
  try {   
          $widget = array_pop(
              json_decode( $this-&gt;api-&gt;get('oembed', array('url' =&gt; $track_url)) )
          );
  
          print_r($widget);
  
      } catch (Exception $e)
      {
          print_r($e-&gt;getMessage());
      }
  </code></pre>
  
  <p>where "track_url" is actually the URL I get back when asking SoundCloud for a track object earlier in the app using the same API. </p>
  
  <p>I'm not actually sure this URL is correct in the first place, because the track object I get back gives the 'uri' in the form:</p>
  
  <pre><code>[uri] =&gt; https://api.soundcloud.com/tracks/62556508
  </code></pre>
  
  <p>The documentation examples all have a straight <a href="http://soundcloud.com/username/track-permalink" rel="nofollow">http://soundcloud.com/username/track-permalink</a> URL - but even using a known path to a public track the attempt to run the API oembed method fails... I still get a 302 Exception.</p>
  
  <p>Finally, there are mentions of setting "allow_redirects" to false in the 'get' command, but this has no effect when I add to the parameters used to build the query to the API. I also tried adding additional cURL options, but that too had no effect.</p>
  
  <p>I have definitely enabled API access to the track within SoundCloud.</p>
  
  <p>Kind of banging my head off the wall on this. If anyone has any pointers I'd be very grateful to hear them. Just for clarity's sake, I am able to access all the user data, comments etc. via the API instance I have created, so it appears to be working fine.</p>