Monday 18 February 2013

Soundcloud API: PHP SDK issue

I tried to fetch track info from the Soundcloud service using 'resolve' method. Code looks like next:
// create a client object with your app credentials
$client = new Services_Soundcloud($clientId, $clientSecret);

// resolve track URL into track resource
$track = json_decode($client->get('resolve', array('url' => $url)));

And I've got fatal error:
Fatal error: Uncaught exception 
'Services_Soundcloud_Invalid_Http_Response_Code_Exception' with message
'The requested URL responded with HTTP code 302.'
in /path-to-project/Services/Soundcloud.php:942

Seems that CURL doesn't follow redirects. It is possible to fix this by setting certain CURL option in Soundcloud class. I've added next to class constructor(line 234):
$this->_curlOptions[CURLOPT_FOLLOWLOCATION] = true;

After that everything started working like a charm.

Problem is already discussed on project google group, so I think the fix will be added to the project repo on GitHub soon.