[API V2] SSL certificate problem?

A place for developers to advertise their TheTVDB.com enabled app and get help from other developers with the API.
Diabetiker
Posts: 1
Joined: Thu Oct 26, 2017 3:58 am

[API V2] SSL certificate problem?

Postby Diabetiker » Fri Oct 27, 2017 4:18 am

Hello :)

I used so far the API V1 would like to change to V2.

I have read a lot of posts in the forum here and tried to rebuild the PHP code to be able to login in the APIs but without success. For examples of this post https://forums.thetvdb.com/viewtopic.php?f=17&t=37746&p=115356&hilit=login#p115356.

I now try the login with php and following the instructions of https://api.thetvdb.com/swagger#!/Authe ... post_login.

but I'm still making a big mistake with the PHP code. Maybe you can help with the problem? I have the feeling that I would approach the API wrongly and not get a proper answer.

My PHP Code:

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors',1);

$url        = "https://api.thetvdb.com/login";
$post_data  = array ('apikey' => '4....................5');
$ch         = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$output     = curl_exec($ch);

if ($output == FALSE)
{
  echo curl_error($ch);   
}
curl_close($ch);
print_r($output);


Results:

Code: Select all

SSL certificate problem: unable to get local issuer certificate


Thank you,

Diabetiker

codegrabber
Posts: 19
Joined: Wed Mar 11, 2015 11:47 am

Re: [API V2] SSL certificate problem?

Postby codegrabber » Sun Nov 19, 2017 3:59 am

Most likely your installation is out of date, resulting in curl not being able to verify the certificate. You can solve that by updating the ca certs that curl uses.

Alternatively, haven't you considered using a library for the communication? They handle all the gritty details for you... For PHP I'm aware of at least two libraries:
- https://github.com/canihavesomecoffee/theTVDbAPI/
- https://github.com/adrenth/thetvdb2