Soundcloud Api Error

2020-01-20 05:13发布

问题:

I was trying to follow a user using soundcloud api in php. But I am getting bellow error when i run the code.

Warning: Missing argument 2 for Services_Soundcloud::put(), called in /home/sumithost/public_html/test.php on line 12 and defined in /home/sumithost/public_html/Soundcloud.php on line 636

exception 'Services_Soundcloud_Invalid_Http_Response_Code_Exception' with message 'The requested URL responded with HTTP code 404.' in /home/sumithost/public_html/Soundcloud.php:941 Stack trace: #0 /home/sumithost/public_html/Soundcloud.php(645): Services_Soundcloud->_request('https://api.sou...', Array) #1 /home/sumithost/public_html/test.php(12): Services_Soundcloud->put('/me/followings/...') #2 {main}exception

My Code is below

require_once 'Soundcloud.php';

$client = new Services_Soundcloud('xxClient-IDxx', 'xxSecretKEYxx', 'http://sumithost.uni.me/sc.php');


$client->setAccessToken('xxAccess-Tokenxx');    


try {
$client->put('/me/followings/3207');
} catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
    echo $e;
}
?>

Using php sdk from here:https://github.com/mptre/php-soundcloud

I think error is in put-function of soundcloud.php:636

回答1:

The put method needs a second argument. The description in the docblock comment is wrong.

/**
 * Send a PUT HTTP request
 *
 * @param string $path        Request path
 * @param array  $postData    Optional post data
 * @param array  $curlOptions Optional cURL options
 *
 * @return mixed
 *
 * @access public
 * @see Soundcloud::_request()
 */

function put($path, $postData, $curlOptions = array())

I think using '' (empty string) as second argument should do the trick.

EDIT: Didn't realize the docblock said its optional. It is not.