Can't post new track via PHP Soundcloud API

只谈情不闲聊 提交于 2019-12-11 09:42:30

问题


I'm in a bit of a pickle here. I developped a Wordpress plugin that helps my site publish sounds to soundcloud directly from the WP back-office. The site has been live for about a year, and I have had no problems until now.

When uploading a track, I get a 'Fatal error: Uncaught exception 'Services_Soundcloud_Invalid_Http_Response_Code_Exception' with message 'The requested URL responded with HTTP code 422.'

I checked if nothing on my code had changed, and it hasn't, the request seems properly formed. Here is the bit of code:

$soundcloud->setAccessToken($_POST['access_token']);

  $mytrack = array(
    'track[title]' => $_POST["audioname"],
    'track[asset_data]' => $_FILES["audiofile"]["tmp_name"]
     );

  $track = json_decode($soundcloud->post('tracks', $mytrack));

Any idea what could be wrong? I have a Pro Unlimited account, so I can't have reached a quota, can I? Other functions used through the API work properly...


回答1:


If you are getting a 422 http code. That's 'Unprocessable entity' error acording to the docs. What it probably mean is that you data structure is wrong.

I don't know the php library you're using but I invite you to try out my own opensource library. https://github.com/njasm/soundcloud . Check the readme. You have an example on how to upload tracks.



来源:https://stackoverflow.com/questions/30277918/cant-post-new-track-via-php-soundcloud-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!