API RETURNING Failed with 0

MY CODE is returning Failed with 0 , i have no idea why

<?php

$ch = curl_init('https://api.twitch.tv/helix/users?login=ninja');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Client-ID: xxx'
));

$data = curl_exec($ch);
$info = curl_getinfo($ch);

curl_close($ch);

if ($info['http_code'] == 200) {
    $data = json_decode($data);
    var_dump($data);
} else {
    echo 'Failed with ' . $info['http_code'];
}



?>

With a 0? That would suggest you got a abnormal error.

print_r($info); to further debug.

Or do the CURL verbosly.

The issue is likely in your PHP Install, and your SSL bundle is out of date/incomplete and you are getting a SSL error, or whatever you are running the code on cannot reach Twitch.

This is not a API issue.

I am Using Easy Php do you think that would be the problem ??

Failed with 0
Array
(
    [url] => https://api.twitch.tv/helix/users?login=ninja
    [content_type] => 
    [http_code] => 0
    [header_size] => 0
    [request_size] => 0
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.141
    [namelookup_time] => 0.047
    [connect_time] => 0.078
    [pretransfer_time] => 0
    [size_upload] => 0
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 0
    [download_content_length] => -1
    [upload_content_length] => -1
    [starttransfer_time] => 0
    [redirect_time] => 0
    [certinfo] => Array
        (
        )

    [primary_ip] => 151.101.134.214
    [primary_port] => 443
    [local_ip] => 192.168.1.40
    [local_port] => 64502
    [redirect_url] => 
)```

Yup.

SSL failed to verify and you didn’t “nicely” catch this issue.

i’m a Php beginner , i really don’t know what that means

Your install of PHP doesn’t know how to handled SSL connections to remote services via cURL

It’s beyond the scope of this forum for such an issue. EasyPHP is not as Easy as it makes out to be.
And google isn’t throwing up anything initially useful to get started/solve this issue.

Usually you’ll find that your CA Cert bundles are out of date or non existant as easyPHP didn’t bother to grab them.

may help you

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.