php-soundcloud icon indicating copy to clipboard operation
php-soundcloud copied to clipboard

"The requested URL responded with HTTP code 0" when getting $accessToken

Open SamSlate opened this issue 10 years ago • 15 comments

require_once 'Services/Soundcloud.php'; include("CLIENT_ID.php");

// create client object with app credentials $soundcloud = new Services_Soundcloud($CLIENT_ID, $CLIENT_SECRET, $REDIRECT_URL);

// Get access token $code = $_GET['code']; try { if(!isset($_SESSION['token'])){ $accessToken = $soundcloud->accessToken($code); $_SESSION['token'] = $accessToken['access_token']; }else{ $soundcloud->setAccessToken($_SESSION['token']); }
} catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) { exit($e->getMessage()); }

returns: "The requested URL responded with HTTP code 0."

I've tried numerous variation on this request but they all receive a code 0, is php access still supported?

SamSlate avatar Apr 30 '14 09:04 SamSlate

Hi All

Just to add to this i am also getting

The requested URL responded with HTTP code 0.

When trying to upload a file through the api.

It will get my data fine but not upload here is my full codeignitor controller

<?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());
        }

    }   
}

sobytes avatar Jun 05 '14 16:06 sobytes

Bump* can anyone help with the above thanks?

sobytes avatar Jun 12 '14 08:06 sobytes

I dont know why but curl says the certificate is expired. So, a (not so secure) way to solve this is put:

                $client->setCurlOptions(array(CURLOPT_SSL_VERIFYPEER => 0));

You put this after constructing a new Services_Soundcloud object...

s0ckz avatar Aug 23 '14 20:08 s0ckz

Getting 'HTTP error code 0' for the first time.

above suggestion from @s0ckz ('CURLOPT_SSL_VERIFYPEER => 0') didn't work for me.

alexweinstein avatar Dec 17 '14 15:12 alexweinstein

I've just started to see this same error, from code that has been working (unchanged) for months. The proposed solution by @s0ckz also did not work for me.

timothywisdom avatar Dec 19 '14 06:12 timothywisdom

I suspect is has something to do with PHP not being happy with an SSL cert. Here's what I've found so far:

http://www.saotn.org/stop-turning-off-curlopt_ssl_verifypeer-and-fix-your-php-config/

timothywisdom avatar Dec 19 '14 06:12 timothywisdom

For what it's worth, I found that the original code (without any SSL adjustments) worked as expected on a different domain and server. Identical code, client_id, and client_secret, updated redirect_url.

@timothywisdom - If you are able to implement that fix (http://www.saotn.org/stop-turning-off-curlopt_ssl_verifypeer-and-fix-your-php-config/), please post specifics here. I wasn't successful.

alexweinstein avatar Dec 19 '14 07:12 alexweinstein

I'm stumped. Even forcing curl to ignore verifying SSL is still giving me the http code 0 error. I tried this:

$accessToken = $soundcloud->accessToken($code, array(), array(
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_SSL_VERIFYHOST => false,
));

This is meant to add the curl options to just the accessToken call (to get the access token). No luck.

I wonder - does this imply my web server is not happy with SoundCloud's SSL certificate? Could it be that SoundCloud's SSL has expired? I would think I'd see more chatter on the internet if that really was the case.

timothywisdom avatar Dec 20 '14 01:12 timothywisdom

FYI - I have also tried telling curl where the updated cacert.pem files are located by

curl_setopt($ch, CURLOPT_CAINFO, '/aboluste/path/to/cacert.pem');

no luck either

timothywisdom avatar Dec 20 '14 01:12 timothywisdom

My site is hosted by Dreamhost. Just had my account moved to a new server cluster and everything works now. Just like it did before the HTTP code 0 errors started popping up—no .pem file needed or adjustments to the SSL. I don't know what the difference is between the servers other than their physical locations (one is east coast USA, the other west coast).

If anyone here can suggest some questions to Dreamhost to help us get to the bottom of this, let me know. I fear that this is just a temporary fix.

alexweinstein avatar Dec 20 '14 05:12 alexweinstein

Wow - I'm on Dreamhost too. Currently on Mortlach.

timothywisdom avatar Dec 20 '14 17:12 timothywisdom

Wow. I was on Draeseke, switched to Yooden-Vranx.

alexweinstein avatar Dec 20 '14 17:12 alexweinstein

OK - thanks for the info. I have SSL installed on my site (free from startssl) and I originally thought that was causing the problem. I've tried reconfiguring it a bunch of different ways with no positive results.

I've sent a support ticket into Dreamhost explaining everything and linking back to this git issue ticket. My hunch is it's something on their end (and not SoundCloud, afterall). I'll post updates as I find out more.

timothywisdom avatar Dec 20 '14 19:12 timothywisdom

I have solved my issue. Dreamhost said SoundCloud updated their DNS and there was a slow DNS resolver (which they "cleared"). My site works again without me doing anything,

timothywisdom avatar Dec 23 '14 00:12 timothywisdom

I have the same issue with our production server. Simply while getting access token from soundcloud it returns with http_code 0. i.e : $soundcloud->getSoundcloudAccessToken => 0 However in development servers it works and returns access_token. btw our production server is not running over https could it be a problem?

rajeevroy15 avatar Mar 06 '17 06:03 rajeevroy15