msteurs
msteurs

Reputation: 21

Soundcloud resolve issue

I am developing an app for SoundCloud, written in PHP and I use the php-soundcloud library.

After successfully having instantiated a Services_Soundcloud instance, I can do calls like the following:

echo $soundcloud->get('me');
echo $soudcloud->get('users/12345678');

However, the following call is not working:

echo $soundcloud->get('resolve', array('url' => 'https://soundcloud.com/webfordreams'));

The error I get is:

Services_Soundcloud_Invalid_Http_Response_Code_Exception: The requested URL responded with HTTP code 302. in Services_Soundcloud->_request() (line 933 of ../php-soundcloud/Services/Soundcloud.php).

After several hours of debugging I decided to ask for help, as I really don't understand what I do wrong.

Can anybody help me and tell me how to get the proper response?

Upvotes: 1

Views: 906

Answers (2)

fhuntern
fhuntern

Reputation: 81

The "HTTP/1.1 302" response that you're getting is the appropriate response according to the api. If you inspect the full php exception you'll get this in the response body:

[httpBody:protected] => {"status":"302 -Found","location":"https://api.soundcloud.com/users/25071103"}

In order to allow CURL to follow the redirect you need to pass the CURLOPT_FOLLOWLOCATION option while calling soundcloud's get() function.

$result = $scloud->get('resolve', array('url' => 'https://soundcloud.com/webfordreams'), array(CURLOPT_FOLLOWLOCATION => TRUE ));

I'm not too sure about the syntax though but what you eventually wanna end up with is something like this in Soundcloud's _request() function:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

Hopefully someone with more experience on this will come along and give you the proper syntax instead of you having to tinker around with the SoundCloud SDK itself.

Upvotes: 1

Malachi
Malachi

Reputation: 33710

Leading on from what Francis.G was saying The syntax you are looking for is:

$soundcloud->get('resolve', array('url' => 'https://soundcloud.com/webfordreams'), array(CURLOPT_FOLLOWLOCATION => true);

The only change is in the definition of the curl-ops array passed into the get() function as the third parameter.

Upvotes: 1

Related Questions