59

I want to collect a list of videos uploaded on a specific channel using the YouTube data API. However, before implementing online I am trying to get my code running on an offline environment (WAMPserver, PHP 5.5.12, Apache 2.4.9). I am using the following code:

require_once 'google-api-php-client-2.0.0-RC5/vendor/autoload.php';

$client = new Google_Client();
$client->setApplicationName("SRC_Thor");
$client->setDeveloperKey("xxxxxxxxxxx");

$youtube = new Google_Service_YouTube($client);

$channelResponse = $youtube->channels->listChannels('contentDetails', []);
var_dump($channelResponse);

However it gives the following error:

Fatal error: Uncaught exception 'GuzzleHttp\Exception\RequestException' with message 'cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)'

I have tried adding the latest version of cacert.pem as most topics on SO offer as a solution, however to no avail.

Machavity
  • 30,841
  • 27
  • 92
  • 100
Sjors Hijgenaar
  • 1,232
  • 1
  • 16
  • 30
  • 2
    Since you're in a development environment, why don't you just set `$client->setDefaultOption('verify', false);` so that it doesn't attempt to perform the verification? Obviously on the live server it won't be an issue given that the live server will have a correct certificate (assumedly) – Ohgodwhy Feb 25 '16 at 21:28
  • 1
    @Ohgodwhy of course, I was put off by all the security thread comments everywhere, but that's a non-issue. Thanks! – Sjors Hijgenaar Feb 25 '16 at 21:35
  • 2
    @Ohgodwhy I am getting an error: `Call to undefined method Google_Client::setDefaultOption()` any idea why? – Sjors Hijgenaar Feb 25 '16 at 21:39
  • 1
    I guess `setDefaultOption` method has been removed from `Google_Client`. Use [@Phung answer](https://stackoverflow.com/a/40487704/5560399) it worked for me! – Elharony Jul 25 '19 at 06:26
  • I find that the closure here is not optimal. Almost none of the answers over there cover the ground where we want to use the google client in testing, from a local dev, where going through setting a certificate is quite inappropriate, whereas answers here mostly address it. I wonder if this one could be phrased differently to insist on the local testing part even more. – Félix Adriyel Gagnon-Grenier Sep 28 '21 at 23:35
  • @Félix Adriyel Gagnon-Grenier if you have any suggestions on how to do that, feel free to help out. It's been very long since I worked on that project and I could really use your help in helping others. – Sjors Hijgenaar Sep 29 '21 at 07:00

8 Answers8

142

If you are on Windows using Xampp, I am stealing a better answer from here, would be helpful if Google shows you this question first.

  1. Download and extract for cacert.pem here (a clean file format/data)

    https://curl.haxx.se/docs/caextract.html

  2. Put it in :

    C:\xampp\php\extras\ssl\cacert.pem

  3. Add this line to your php.ini

    curl.cainfo = "C:\xampp\php\extras\ssl\cacert.pem"

  4. restart your webserver/Apache

Community
  • 1
  • 1
Phung D. An
  • 2,402
  • 1
  • 22
  • 23
48

Seeing I am using a local environment I can safely disable SSL, which i did using the following:

$guzzleClient = new \GuzzleHttp\Client(array( 'curl' => array( CURLOPT_SSL_VERIFYPEER => false, ), ));
$client->setHttpClient($guzzleClient);

Where $client is my Google_Client().

Sjors Hijgenaar
  • 1,232
  • 1
  • 16
  • 30
30
$guzzleClient = new \GuzzleHttp\Client(['verify' => false]);

Guzzle version 6

You could refer to Guzzle Docs at

http://docs.guzzlephp.org/en/latest/request-options.html#verify

lijinma
  • 2,914
  • 1
  • 23
  • 22
28

I work with xamps nothing of the above did work for me

I tried this and it worked

  1. open vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php

and change this

$conf[CURLOPT_SSL_VERIFYHOST] = 2;
$conf[CURLOPT_SSL_VERIFYPEER] = true;

to this

$conf[CURLOPT_SSL_VERIFYHOST] = 0;
$conf[CURLOPT_SSL_VERIFYPEER] = FALSE;

it's a temporary solution if you updated this file the changes will lost

Muhammad Hassaan
  • 7,296
  • 6
  • 30
  • 50
5

for the essence of development and testing, You have two options to a quick fix

  1. Use
$client = new GuzzleHttp\Client();
$request = $client->request('GET',$url, ['verify' => false]); //where $url is your http address
  1. follow @Pham Huy Anh answer's above then do this
$client = new GuzzleHttp\Client();
$request = $client->request('GET',$url, ['verify' => 'C:\xampp\php\extras\ssl\cacert.pem']);

Hope it helps someone.

Ankur Bhadania
  • 4,123
  • 1
  • 23
  • 38
walecloud
  • 306
  • 3
  • 5
1

PCI-DSS 3.1 requires all SSL to only TLS 1.2 so a lot of providers are simply turning everything but TLS 1.2 off. I ran into this type of issue where CURL saw the failure to downgrade handshakes as a failure to verify the SSL certificate. Try finding where your code is doing the CURL call and add this line (be sure to replace $ch with whatever CURL handle your code uses)

curl_setopt($ch, CURLOPT_SSLVERSION, 6);  // Force TLS 1.2
Machavity
  • 30,841
  • 27
  • 92
  • 100
  • how doI find the CURL handle my code uses? I run locally with a WAMPserver – Sjors Hijgenaar Feb 29 '16 at 18:53
  • is curl_init() a proper way? Setting the SSLVERSION to 6 doesn't solve the problem. Setting SSL_VERIFYPEER to false doesn't work either. – Sjors Hijgenaar Feb 29 '16 at 18:59
  • There will be a line in your code using `curl_init();` to initialize the CURL request. If setting TLS 1.2 doesn't work I'm not sure what else could be wrong. – Machavity Feb 29 '16 at 20:13
0

it also worked for me by downloading the cert from the link https://gist.github.com/VersatilityWerks/5719158/download then save it in C:\xampp\php\extras\ssl then edit php.ini. To get Php.ini quickly see the figure below enter image description here

Then STOP and reStart your apache again. it worked well !!!

kimoduor
  • 504
  • 6
  • 16
-3
$guzzleClient = new \GuzzleHttp\Client(['verify' => false]);
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
  • 3
    This appears to be identical to the code in [the answer](https://stackoverflow.com/a/40623254/1575353) by lijnma... it doesn't appear to add anything beyond it... – Sᴀᴍ Onᴇᴌᴀ Jun 21 '17 at 16:37