Soundcloud php API请求的URL以HTTP代码0响应

时间:2014-06-12 08:15:54

标签: php http soundcloud

尝试使用soundcloud php api将文件上传到soundcloud时,我收到以下回复。

  

请求的URL以HTTP代码0响应。

尝试通过api上传文件时。

它会使我的数据正常,但不在这里上传是我的完整codeignitor控制器。

我已经尝试了所有建议的选项来添加CURLOPT_SSL_VERIFYPEER,false但这似乎对我有用,有人可以确认它正在工作,所以我可以缩小到我的服务器。

<?php defined('BASEPATH') OR exit('No direct script access allowed');

/*
 * Soundcloud Controller
 */

class Soundcloud extends CI_Controller {


    /**
     * Constructor
     */
    function __construct()
    {
        parent::__construct();
        require APPPATH.'/libraries/php-soundcloud-master/Services/Soundcloud.php';
        $this->soundcloud = new Services_Soundcloud('api key', 'api key', 'redirect uri');

    }

    function index(){
        $authorizeUrl = $this->soundcloud->getAuthorizeUrl();
        // Redirect to authorize url
        echo '<a href="' . $authorizeUrl . '">Connect with SoundCloud</a>';
    }

    function getme(){

        $url = $_SERVER['DOCUMENT_ROOT'] . '/' . APPPATH . 'libraries/php-soundcloud-master/test/test.mp3';
        try {
            $accessToken = $this->soundcloud->accessToken($_GET['code']);
        } catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
            exit($e->getMessage());
        }

        /*
        $this->soundcloud->setCurlOptions(array(
            CURLOPT_SSL_VERIFYHOST => 0,
            CURLOPT_SSL_VERIFYPEER => 0
        ));
        */
        try {
            $me = json_decode($this->soundcloud->get('me'), true);
        } catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
            exit($e->getMessage());
        }

// this will print out all my data fine
        echo "<pre>";
            print_r($me);
        echo "</pre>";
        $track_data = array(
            //'track[sharing]' => 'private',
            'track[title]' => 'Testing API',
            //'track[tags]' => null,
            'track[asset_data]' => '@' . $url
        );
        // perform the actual upload to soundcloud.
        try {
            $response = json_decode(
                $this->soundcloud->post('tracks', $track_data),
                true
            );
        } catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
            show_error($e->getMessage());
        }

    }   
}

0 个答案:

没有答案